Python:带有 PhantomJS 空页面源的 Selenium [英] Python: Selenium with PhantomJS empty page source

查看:34
本文介绍了Python:带有 PhantomJS 空页面源的 Selenium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想获取 URL 页面的源时,我在 Windows7 上遇到了 Selenium 和 PhantomJS 的问题.browser.page_source 仅返回 .我在 browser.page_source 之前睡过,但没有帮助.

I'm having trouble with Selenium and PhantomJS on Windows7 when I want to get the source of the page of an URL. browser.page_source returns only <html><head></head></html>. I've put a sleep before browser.page_source but it didn't help.

这是我的代码:

from selenium import webdriver
browser = webdriver.PhantomJS('phantomjs-1.9.7-windowsphantomjs.exe')
url = 'myurl'
browser.get(url)
print browser.page_source

在具有相同版本 PhantomJS 的 Linux 上,它可以完美运行.它也适用于 Windows Server 2003.

On Linux with the same version of PhantomJS it works perfectly. Also it works on Windows Server 2003.

推荐答案

phantomjs 默认使用 SSLv3,但是许多站点在 ssl 中的 bug 之后迁移到 tls.这就是为什么你有空白页.使用 service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any']

by default phantomjs use SSLv3, but many sites after bug in ssl migrate to tls. That's why you has blank page. use service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any']

browser = webdriver.PhantomJS('phantomjs-1.9.7-windowsphantomjs.exe', service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])

这篇关于Python:带有 PhantomJS 空页面源的 Selenium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆