PhantomJS与Selenium的错误。消息:'phantomjs'可执行文件需要在PATH中。[英] PhantomJS with Selenium error: Message: 'phantomjs' executable needs to be in 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/<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

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

推荐答案

我在命令行中用这个命令解决了同样的问题

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

如果/home/login/phantomjs/bin 是具有可执行文件"phantomjs"的文件夹的路径,则可以使用.

本文地址:https://www.itbaoku.cn/post/1739824.html