如何在启动时使用Python错误从网页调用PhantomJS

2024-05-15 13:18:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用Python、Selenium和PhantomJS创建一个基于web的scraper,在这里可以将url输入到表单中,并且scrape的结果将返回到web页面。我可以在我的个人电脑上运行它,也可以让它通过终端工作。在

它位于安装了Python3.5的Dreamhost共享主机上的虚拟环境中。我已经测试过,这些参数可以很好地传递,而且它只使用lxml和请求就可以工作了。但是,当我尝试使用PhantomJS从网页上的表单运行脚本时,它不能正常工作。返回以下错误。。。在

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

我尝试了一些不同的变化,期望的功能,甚至改变文件权限的一切在虚拟环境中,但没有效果。我一定是错过了什么,还是不可能?如有任何建议,不胜感激。在


Tags: inpyselfhomebinremoterequestlib