我正在运行PhantomJS
driver = webdriver.PhantomJS(executable_path='E:\phantomjs\bin\phantomjs.exe')
但该计划失败了,说
AttributeError:模块'selenium.webdriver'没有属性'PhantomJS'。
操作系统是Windows 10.我的python版本是3.6,selenium版本是3.8.0,而phantomjs版本是2.1.1。所有这些都是最新的。
谢谢,如果有人可以提供一个手!
以下是selenium version的截图。
当您在路径中使用单引号(\)
时,您应该按原样传递原始(r)
开关:
driver = webdriver.PhantomJS(executable_path=r'E:\phantomjs\bin\phantomjs.exe')
如果错误仍然存在,请通过Command Prompt
检查以下内容:
Selenium
版本:
>pip show -V selenium
您必须看到如下输出:
Name: selenium
Version: 3.8.0
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: c:\python\lib\site-packages
Requires:
packages
:
>pip freeze
您必须看到如下输出:
Selenium==3.8.0
如果以下命令失败,则表示未正确安装Selenium
。所以你必须这样做:
>pip install -U selenium
作为替代方案,您可以卸载Selenium
并重新安装,如下所示:
>pip uninstall selenium
>pip install -U selenium
这是完整的Installation Instructions
供您参考。
我已经解决了这个问题。原因是我使用pycharm作为IDE。我使用虚拟环境创建项目。这就是为什么我不能使用我安装的库。
无论如何,谢谢你的帮助!