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

时间:2016-06-19 02:53:05

标签: python selenium selenium-webdriver phantomjs

我正在尝试运行此脚本:

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

但是,脚本在<?php class MyComponent { /** * @param mysqli $mysqli */ public function __construct($mysqli) { $this->mysqli = $mysqli; } public function getBars() { $bars = $this->mysqli->query('...'); return $bars; } } // now back in the global scope $mysqli = mysqli_connect('localhost', 'joe', 'secret', 'foodb'); $component = new MyComponent($mysqli); $bars = $component->getBars(); 行失败并出现以下错误

session = webdriver.PhantomJS()

如何将phantomj添加到PATH中?我正在运行ubuntu 16.04并通过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 安装了selenium。

7 个答案:

答案 0 :(得分:11)

您需要下载DRIVER

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

答案 1 :(得分:10)

工作解决方案:

假设你在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,例如此示例 enter image description here

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

答案 2 :(得分:5)

我在命令行中使用此命令解决了相同的promlem

const addMinuteToTime = (time,minutesAdd) => {
  const hoursMinutes = time.split(":");
  const hours = parseInt(hoursMinutes[0]);
  const minutes = hoursMinutes[1] ? parseInt(hoursMinutes[1]) : 0;
  timee = ((hours * 60 + minutes + minutesAdd ) / 60).toFixed(2) ; 
  let [newHours, newMinutess] = timee.toString().split('.') 
  newMinutess  =Math.round( newMinutess /100 * 60)  || "00"
  return newHours+":"+newMinutess
}
console.log(addMinuteToTime("10:10",60))

如果/ home / login / phantomjs / bin是包含可执行文件'phantomjs'的文件夹的路径,那么它是有用的。

答案 3 :(得分:1)

您需要提供可执行文件路径。这适用于Linux或更准确地说是Ubuntu。

您应指定可执行文件路径(完整),而不是包含可执行文件的目录路径。

driver = webdriver.PhantomJS(executable_path='Complete path/to/phantomjs')

它不需要任何驱动程序。

在Ubuntu 16.04上为我工作得很好。

答案 4 :(得分:0)

为什么您不使用有史以来最简单的方法来超越phantomjs.exe

进入已经添加到系统环境中的Python脚本目录 python目录路径应该是这样

C:\Users\[user]\AppData\Local\Programs\Python\Python[version]\Scripts
# you can use it as following 
from selenium import webdriver
driver = webdriver.PhantomJS()

答案 5 :(得分:0)

1。从https://phantomjs.org/download.html下载Phantomjs可执行文件 2.将phantomjs.exe复制到C:\ Python27 \ Lib \ site-packages \ selenium \ webdriver \ phantomjs 3.在环境变量键“ PATH”下添加路径C:\ Python27 \ Lib \ site-packages \ selenium \ webdriver \ phantomjs

由于我正在使用PyCharm,因此必须在完成上述设置后重新启动Pycharm

答案 6 :(得分:0)

这将很好地工作。

?listen