2016-01-13 129 views
1

我想用PhantomJS()在python3.4和类型硒:webdriver.PhantomJS(): “错误:无法连接到GhostDriver端口51263”

因此:

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 

回答

0

您必须下载phantomJS - LINK

,之后给予路径它在你的代码

browser = webdriver.PhantomJS(pathToPhantomJS) 
+1

的答复@Barkan感谢,但phantomjs是安装并插入路径也没有工作。 – S1J0

相关问题