0

I want to create a web based scraper using Python, Selenium and PhantomJS where you can input a url into a form and the results from the scrape will be returned to the webpage. I can run it on my PC and I can also get it to work through the terminal.

It is located in a virtual environment on Dreamhost shared hosting with Python3.5 installed. I have tested that the parameters are being passed in fine, and it does work using just lxml and requests. However, when I try to run the script from the form on the webpage using PhantomJS then it doesn't work properly. The following error in returned...

Traceback (most recent call last):
  File "testscrape.py", line 140, in <module>
    driver = init_driver()
  File "testscrape.py", line 69, in init_driver
    driver = webdriver.PhantomJS(executable_path=phantomPATH,desired_capabilities=dcap)
  File "/home/paul/.python35/bin/magenv/lib/python3.5/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 56, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/paul/.python35/bin/magenv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 91, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/home/paul/.python35/bin/magenv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 173, in start_session
    'desiredCapabilities': desired_capabilities,
  File "/home/paul/.python35/bin/magenv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 231, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/home/paul/.python35/bin/magenv/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
    return self._request(command_info[0], url, body=data)
  File "/home/paul/.python35/bin/magenv/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 463, in _request
    resp = opener.open(request, timeout=self._timeout)
  File "/home/paul/.python35/lib/python3.5/urllib/request.py", line 465, in open
    response = self._open(req, data)
  File "/home/paul/.python35/lib/python3.5/urllib/request.py", line 483, in _open
    '_open', req)
  File "/home/paul/.python35/lib/python3.5/urllib/request.py", line 443, in _call_chain
    result = func(*args)
  File "/home/paul/.python35/lib/python3.5/urllib/request.py", line 1268, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/home/paul/.python35/lib/python3.5/urllib/request.py", line 1243, in do_open
    r = h.getresponse()
  File "/home/paul/.python35/lib/python3.5/http/client.py", line 1174, in getresponse
    response.begin()
  File "/home/paul/.python35/lib/python3.5/http/client.py", line 282, in begin
    version, status, reason = self._read_status()
  File "/home/paul/.python35/lib/python3.5/http/client.py", line 243, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/home/paul/.python35/lib/python3.5/socket.py", line 575, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

I have tried a few different variations of desired_capabilities and even changing file permissions of everything in the virtual environment but to no avail. I must be missing something, or is it just not possible? Any suggestions gratefully received.

Paul Kerr
  • 31
  • 4
  • I don't think it's your mistake, try accessing to a different url and see if you get the same error -> [relevant SO question](http://stackoverflow.com/questions/20568216/python-handling-socket-error-errno-104-connection-reset-by-peer) – Rafael Almeida May 08 '16 at 16:14
  • thanks for the link - however, the error occurs with the initialization of PhantomJS and so it can't be the url... – Paul Kerr May 08 '16 at 23:23
  • Oh yeah, my bad, if you open your command line and execute `phantomjs version` does it recognize the command? Did you make sure your "dcap" variable matches the phantomjs path executable? – Rafael Almeida May 08 '16 at 23:28

0 Answers0