【问题标题】:selenium: webdriver.PhantomJS(): "Error: Can not connect to GhostDriver on port 51263"selenium:webdriver.PhantomJS():“错误:无法连接到端口 51263 上的 GhostDriver”
【发布时间】:2016-01-13 14:54:41
【问题描述】:

我想在python3.4中使用PhantomJS()并输入

因此:

from selenium import webdriver
browser = webdriver.PhantomJS()

我得到了错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
    self.service.start()
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/phantomjs/service.py", line 83, in start
    "Can not connect to GhostDriver on port {}".format(self.port))
selenium.common.exceptions.WebDriverException: Message: Can not connect to GhostDriver on port 40236

我知道错误是在selenium.webdriver.phantomjs.service 内部抛出的,因为函数utils.is_connectable(self.port) 无法连接到本地主机(本地主机是可达的)。

try:
    self.process = subprocess.Popen(
        self.service_args, stdin=subprocess.PIPE,
        close_fds=platform.system() != 'Windows', 
        stdout=self._log, stderr=self._log)
except Exception as e:
    raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
count = 0
while not utils.is_connectable(self.port):
    count += 1
    time.sleep(1)
    if count == 30:
        raise WebDriverException("Can not connect to GhostDriver on port {}".format(self.port))

我找不到适合我的解决方案,所以如果有人有想法就会创建。

我的系统:

Linux controller 4.1.15-v7+ #830 SMP Tue Dec 15 17:02:45 GMT 2015 armv7l GNU/Linux

【问题讨论】:

    标签: python selenium phantomjs ghostdriver


    【解决方案1】:

    你必须下载 phantomJS - LINK

    然后在你的代码中给出路径

    browser = webdriver.PhantomJS(pathToPhantomJS)
    

    【讨论】:

    • @Barkan 感谢您的回复,但是安装了 phantomjs 并且插入路径也不起作用。
    猜你喜欢
    • 2013-07-23
    • 2014-01-21
    • 2016-09-05
    • 1970-01-01
    • 2017-07-02
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    相关资源
    最近更新 更多