2016-06-19 77 views
11

我试图运行此脚本:PhantomJS硒错误:消息:“phantomjs”可执行文件需要在PATH

https://github.com/Chillee/coursera-dl-all

然而,该脚本在行session = webdriver.PhantomJS()失败,出现以下错误

Traceback (most recent call last): 
    File "dl_all.py", line 236, in <module> 
    session = webdriver.PhantomJS() 
    File "/home/shaan/.local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__ 
    self.service.start() 
    File "/home/shaan/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 69, in start 
    os.path.basename(self.path), self.start_error_message) 
selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. 

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x7f6f632864d0>> ignored 

如何将phantomjs添加到我的PATH中?我运行Ubuntu 16.04并通过npm install selenium安装硒。

+0

是否安装了phantomjs? –

+0

应该是。有什么方法我可以仔细检查? – quantumbutterfly

+1

做'哪个phantomjs'。如果不在那里,只需将其移动到/ usr/bin或PATH中的任何其他位置 – pguardiario

回答

9

你需要的session = webdriver.PhantomJS("c:\driverPath")

6

工作液后下载DRIVER

Assumming你是在Windows上 - 它是Linux类似这里

1)下载phantomjs:http://phantomjs.org/download.html选择windows/linux相应地

2)解压缩你的phantomjs-2.1.1-windows.zip并保存到例如C盘,如C:\ phantomjs-2.1.1-windows \ bin(在这里有一个phantomjs.exe,是你的系统需要执行的)

3)在Windows10编辑环境路径包括这个bin文件夹C:\ phantomjs-2.1.1-WINDOWS \斌如本例中 enter image description here

4),你可能会或可能无法重新启动您的计算机。完成!它应该工作! (webdriver的查找phantomjs.exe,它现在应该准备好)

1

我在命令行解决同promlem用这个命令

export PATH=${PATH:+$PATH:}/home/<login>/phantomjs/bin 

这是工作,如果/家庭/登录/ phantomjs/bin目录的路径文件夹与可执行'phantomjs'。

相关问题