当我想要获取URL页面的源代码时,在Windows7上使用Selenium和PhantomJS遇到了问题。browser.page_source
仅返回<html><head></head></html>
。我在browser.page_source
之前先睡了一觉,但它没有帮助。
这是我的代码:
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 Server2003上运行。
发布于 2015-12-14 07:23:19
默认情况下,phantomjs使用SSLv3,但许多网站在ssl中出现错误后会迁移到tls。这就是为什么你有空白页面的原因。使用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'])
发布于 2014-06-24 19:17:32
使用service_args=['--ignore-ssl-errors=true']
做到了!
browser = webdriver.PhantomJS('phantomjs-1.9.7-windows\phantomjs.exe', service_args=['--ignore-ssl-errors=true'])
发布于 2016-09-27 21:45:15
driverPhantom = webdriver.PhantomJS(driverLocation, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any']) # initaling web driver for PhantomJs
对我很管用。
https://stackoverflow.com/questions/23581291
复制相似问题