Python: Selenium with PhantomJS empty page source

匿名 (未验证) 提交于 2019-12-03 02:48:02

问题:

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 . I've put a sleep before browser.page_source but it didn't help.

This is my code:

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

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

回答1:

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']) 


回答2:

Using service_args=['--ignore-ssl-errors=true'] did the trick !

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


回答3:

driverPhantom = webdriver.PhantomJS(driverLocation, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])      # initaling web driver for PhantomJs 

Worked for me.



回答4:

increasing the screen size as below worked for me:

driver = webdriver.PhantomJS(path2phantom, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any']) 
driver.set_window_size(2000, 1500)


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!