gpt4 book ai didi

python - selenium python 无法与 phantomjs 一起使用

转载 作者:太空宇宙 更新时间:2023-11-03 18:37:55 25 4
gpt4 key购买 nike

我已经通过 python 使用 npm 和 selenium-python 安装了 phantomjs。

Headless Firefox 一切正常,但 phantomjs 则不行。

这是代码。

In [1]: from selenium import webdriver

In [2]: browser = webdriver.PhantomJS()

In [3]: browser.get('http://www.google.com/')

---------------------------------------------------------------------------
CannotSendRequest Traceback (most recent call last)
<ipython-input-5-a95426e05380> in <module>()
----> 1 browser.get('http://www.google.com/')

/home/asit/pyrepo/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyc in get(self, url)
174 Loads a web page in the current browser session.
175 """
--> 176 self.execute(Command.GET, {'url': url})
177
178 @property

/home/asit/pyrepo/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyc in execute(self, driver_command, params)
160
161 params = self._wrap_value(params)
--> 162 response = self.command_executor.execute(driver_command, params)
163 if response:
164 self.error_handler.check_response(response)

/home/asit/pyrepo/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.pyc in execute(self, command, params)
353 path = string.Template(command_info[1]).substitute(params)
354 url = '%s%s' % (self._url, path)
--> 355 return self._request(url, method=command_info[0], data=data)
356
357 def _request(self, url, data=None, method=None):

/home/asit/pyrepo/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.pyc in _request(self, url, data, method)
381 headers["Authorization"] = "Basic %s" % auth
382
--> 383 self._conn.request(method, parsed_url.path, data, headers)
384 resp = self._conn.getresponse()
385 statuscode = resp.status

/usr/lib/python2.7/httplib.pyc in request(self, method, url, body, headers)
956 def request(self, method, url, body=None, headers={}):
957 """Send a complete request to the server."""
--> 958 self._send_request(method, url, body, headers)
959
960 def _set_content_length(self, body):

/usr/lib/python2.7/httplib.pyc in _send_request(self, method, url, body, headers)
984 skips['skip_accept_encoding'] = 1
985
--> 986 self.putrequest(method, url, **skips)
987
988 if body and ('content-length' not in header_names):

/usr/lib/python2.7/httplib.pyc in putrequest(self, method, url, skip_host, skip_accept_encoding)
854 self.__state = _CS_REQ_STARTED
855 else:
--> 856 raise CannotSendRequest()
857
858 # Save the method we use, we need it later in the response phase

CannotSendRequest:

有什么解决办法吗?

最佳答案

确保您至少使用 PhantomJS 1.8,直到该版本他们才支持 webdriver 连接。我知道昨天我经历这个的时候我的包管理器有一个更旧的版本。 http://phantomjs.org/release-1.8.html

关于python - selenium python 无法与 phantomjs 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21185840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com