Python selenium调用phantomjs问题
使用selenium调用火狐,谷歌浏览器都可以实现js的跳转,但是使用phantomjs抓取的内容却是一个js跳转方法。很奇怪为什么这条js没有执行,一般来说即使js执行失败也应该有异常之类的啊。
以下是抓取到的js页面内容:
以下是抓取到的js页面内容:
<html><head>
<script type="text/javascript">
window.onload = function() {
// Parse the tracking code from cookies.
var trk = "sentinel_org_block";
var cookies = document.cookie.split("; ");
for (var i = 0; i < cookies.length; ++i) {
if ((cookies[i].indexOf("trkCode=") == 0) && (cookies[i].length > 8)) {
trk = cookies[i].substring(8);
}
}
// Get the protocol for the redirect url.
var protocol = "http:";
if (window.location.protocol == "https:") {
protocol = "https:";
} else {
// If "sl" cookie is set, redirect to https.
for (var i = 0; i < cookies.length; ++i) {
if ((cookies[i].indexOf("sl=") == 0) && (cookies[i].length > 3)) {
window.location.href = "https:" + window.location.href.substring(window.location.protocol.length);
return;
}
}
}
// Get the new domain. For touch.www.linkedin.com or tablet.www.linkedin.com
// we strip "touch." and "tablet.". For international domains such as
// fr.linkedin.com, we convert it to www.linkedin.com
var domain = location.host;
if (domain.substr(0, 6) == "touch.") {
domain = domain.substr(6);
} else if (domain.substr(0, 7) == "tablet.") {
domain = domain.substr(7);
} else if (domain.charAt(2) == ".") {
domain = "www" + domain.substr(2);
}
window.location.href = "https://" + domain + "/uas/login?trk=" + trk + "&session_redirect=" +
encodeURIComponent(protocol + "//" + domain +
window.location.href.substr(window.location.href.search(window.location.host) +
window.location.host.length));
}
</script>
</head><body>
</body></html>
...全文
相关推荐
python selenium chrome 多开 多线程
在Python中,我们可以使用`selenium`库来调用Selenium的功能。2.
Python-fbadmin基于selenium和phantomjs完成的facebook群管理工具
然后,通过调用Python脚本并传入相应的参数,启动fbadmin进行自动化的Facebook群组管理。
selenium-phantomjs:使用Selenium Web驱动程序和PhantomJS下载HTML源代码-html source download
**Python编程**:在实际操作中,通常会用Python作为Selenium和PhantomJS的编程语言,因为Python有丰富的库支持,且语法简洁。
python的《Selenium爬虫》中文版
- **其他问题**:解决常见问题,如中文编码问题、不同 frame 间的转换等。
phantomjs-2.1.1-windows
使用PhantomJS时,你需要先安装它,解压“phantomjs-2.1.1-windows”压缩包后,将可执行文件路径添加到系统环境变量,这样就可以在Python代码中调用它了。


