PhantomJS与Selenium错误:消息:'phantomjs'可执行文件需要在PATH中

qua*_*fly 19 python selenium phantomjs selenium-webdriver

我正在尝试运行此脚本:

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/<user>/.local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
    self.service.start()
  File "/home/<user>/.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
Run Code Online (Sandbox Code Playgroud)

如何将phantomj添加到PATH中?我正在运行ubuntu 16.04并通过安装selenium npm install selenium.

Leo*_*kan 16

你需要下载DRIVER

之后 session = webdriver.PhantomJS("c:\driverPath")

  • 在Windows上,它应类似于`session = webdriver.PhantomJS(executable_path ='C:\\ Phantomjs \\ bin \\ phantomjs')',其中最后一个“ phantomjs”代表phantomjs.exe (2认同)
  • 在 PhantomJS 上工作了几个小时以找出问题所在后,我得到的最后一个错误是“Selenium 对 PhantomJS 的支持已被弃用”。向我学习,不要在这个模块上浪费您的宝贵时间。 (2认同)

Dun*_*ung 13

工作方案:

假设你在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\bin,例如此示例 在此输入图像描述

4)您可能会或可能不会重启您的机器.完成!它应该工作!(Webdriver寻找phantomjs.exe,现在应该准备好了)


小智 5

我在命令行中使用此命令解决了同样的问题

export PATH=${PATH:+$PATH:}/home/<login>/phantomjs/bin
Run Code Online (Sandbox Code Playgroud)

如果/ home / login / phantomjs / bin是带有可执行文件'phantomjs'的文件夹的路径,则可以使用。