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.
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.
"Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead" #48.
Key Differences Between Selenium and PhantomJS Being a headless browser, the interactions are much faster than the real browser. So the performance time is smoother in PhantomJS than in Selenium.
Selenium PhantomJS To use the PhantomJS webdriver, all you need to do is change it to PhantomJS(). Then will This will work with both Python 2.7 and Python 3. On Windows, the path should be changed to the location of your phantomjs installation.
PhantomJS is a headless Webkit, which has a number of uses. In this example, we'll be using it, in conjunction with Selenium WebDriver, for conducting basic system tests directly from the command line. Since PhantomJS eliminates the need for a graphical browser, tests run much faster.
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'])
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'])
driverPhantom = webdriver.PhantomJS(driverLocation, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any']) # initaling web driver for PhantomJs
Worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With