1

I have PhantomJS 1.9.0 installed.

I tried the following code to download the page and show the HTML.

from selenium import webdriver

driver = webdriver.PhantomJS(service_args=['--ignore-ssl-   errors=true'])
page = driver.get('http://example.com')
print(page.page_source)

I get the following error:

/usr/bin/python3.4 phantom.py
Traceback (most recent call last):
File "phantom.py", line 5, in <module>
print(page.page_source)
AttributeError: 'NoneType' object has no attribute 'page_source'

Clearly it means that driver.get isn't working but the reason?

1
  • get is an issue an inplace operation, just call get then print driver.get_source Commented Mar 11, 2016 at 0:59

2 Answers 2

2

The problem is that you're calling the page_source attribute on the page variable, which is incorrect. All the get method does is navigate to the URL specified in the parameter, but it does not return anything to be stored in the page variable, which is why the error indicates it is a NoneType object. What you need to do is call the attribute on the driver variable.

from selenium import webdriver
driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'])
print(driver.page_source)
Sign up to request clarification or add additional context in comments.

Comments

1

I currently don't have a good explanation as to why, but assigning page like that doesn't work for some reason

from selenium import webdriver

driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'])
driver.get('http://example.com')
html_content = driver.page_source
print(html_content)
driver.close()

I'm going to keep looking and go read the documentation to see if I can find out why this is

3 Comments

Thanks for the response. I update the code but now I am getting the error that 'Message: Can not connect to the Service /usr/bin/phantomjs'. I have it installed already. phantomjs is at /usr/bin/phantomjs
@conquester be mindful of your spacing and you should be ok --ignore-ssl-errors=true it's all one hyphenated arg
Thanks for that. I totally missed it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.