模块“selenium.webdriver”没有属性“PhantomJS”

Sus*_*usu 12 python selenium phantomjs

我正在运行 PhantomJS

driver = webdriver.PhantomJS(executable_path='E:\phantomjs\bin\phantomjs.exe')
Run Code Online (Sandbox Code Playgroud)

但程序失败了,说

AttributeError:模块“selenium.webdriver”没有属性“PhantomJS”。

操作系统是Windows 10。我的python版本是3.6,selenium版本是3.8.0,phantomjs版本是2.1.1。所有这些都是最新的。

如果有人可以伸出援手,谢谢!

以下是selenium版本的截图。

Olg*_*ski 10

当我在谷歌中寻找答案时,我提请注意这个问题。我花了相当多的工作才找到这个问题的答案,所以为了给其他人节省一些工作,虽然这个问题已经过去了很多时间,但我建议你现在不要使用 PhantomJS。在 Selenium 的官方网站上https://www.selenium.dev/documentation/getting_started/installing_browser_drivers/上,你可以读到这样一句话:“PhantomJS 是一个基于 Webkit 的无头浏览器,尽管它的版本比 Google Chrome 或Safari。虽然历史上是一个流行的选择,但现在明智的做法是避免 PhantomJS。该项目自 2017 年 8 月 5 日起就不再维护,因此虽然网络将继续变化,但 PhantomJS 不会更新。这是在 Google 宣布无头运行 Chrome 的能力,现在 Mozilla\xe2\x80\x99s Firefox 也提供了这种功能。” 我换成Mozilla\xe2\x80\x99s Firefox(我无头使用)。

\n


Deb*_*anB 2

(\)当您在路径中使用单引号时,您应该传递原始(r)开关,如下所示:

driver = webdriver.PhantomJS(executable_path=r'E:\phantomjs\bin\phantomjs.exe')
Run Code Online (Sandbox Code Playgroud)

更新 :

如果错误仍然存​​在,请检查以下内容Command Prompt

如果以下命令失败则表示Selenium没有正确安装。所以你必须这样做:

>pip install -U selenium
Run Code Online (Sandbox Code Playgroud)

作为替代方案,您可以卸载 Selenium并重新安装,如下所示:

>pip uninstall selenium
>pip install -U selenium
Run Code Online (Sandbox Code Playgroud)

这是完整的Installation Instructions供您参考。