20

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.

5
  • Try some debugging, capture a screenshot for example Commented May 12, 2014 at 21:31
  • 3
    The screenshot is empty, blank image. I thought that it's a problem with PhantomJS and I've tried to load the page with PyQt4's webkit but the result is the same, just <html> and <head> tags. This is the URL which gives me this headache: homesearch.com/browse?fulltextquery=miami+fl&page=0 Commented May 13, 2014 at 22:33
  • I've encountered the same issue when navigated to some https://url. Use time.sleep(few_seconds) or webdriver's expected conditions to wait for some element to be present on page after calling browser.get(url) Commented May 13, 2014 at 23:47
  • also try to creat a driver instance with these params browser = webdriver.PhantomJS('phantomjs-1.9.7-windows\phantomjs.exe', service_args=['--ignore-ssl-errors=true']) Commented May 14, 2014 at 11:38
  • I've used a sleep of 15-20 seconds and the result was the same. I will try with service_args. Commented May 14, 2014 at 17:15

4 Answers 4

35

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'])
Sign up to request clarification or add additional context in comments.

4 Comments

Upvoted this because using just the ignore ssl error did not work for me but adding ssl protocol any suggested by this comment help. Kudos
Be aware that --ignore-ssl-errors is dangerous and you shouldn't use it unless you know what you're doing. The other option will probably fix most issues.
@AlexW this solution is worked for me, but I don't know under the hood about this. Could you elaborate about the dangerous using --ignore-ssl-errors or provide some reference about this?
I have a related question: How can we found these selenium phantomjs usages? I think it's very hard for me to find these usages in seleniumhq.org/docs
8

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

1 Comment

I am using webdriver.Remote as I am running a phantomJS remotely. Do you know how to pass the service_args if this is the case?
2
driverPhantom = webdriver.PhantomJS(driverLocation, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])      # initaling web driver for PhantomJs

Worked for me.

Comments

0

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.