当我想获取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 Server 2003。
默认情况下,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'])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句