Python:Selenium与PhantomJS空页面源 [英] Python: Selenium with PhantomJS empty page source

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

问题描述

当我想获取URL页面的源时,我在Windows7上使用Selenium和PhantomJS遇到了麻烦. browser.page_source仅返回<html><head></head></html>.我已经在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-windows\phantomjs.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中的错误后许多站点都迁移到了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-windows\phantomjs.exe', service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])

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

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