WebDriverException: Message: 'phantomjs.exe' executable needs to be in PATH.

来源:互联网 发布:软件系统业务需求 编辑:程序博客网 时间:2024/05/13 07:21

网上的某测试代码:

from selenium import webdriver  driver = webdriver.PhantomJS(executable_path="C:\Python27\Scripts\phantomjs-2.1.1-windows\bin\phantomjs.exe")  driver.get("http://www.baidu.com")  data = driver.title  print data 
配置环境变量path

C:\Python27\Scripts\phantomjs-2.1.1-windows\bin

无效(此处发现有人的错误是路径一直写到了xxx.exe

检查源程序

发现自己原来把Scripts打成了Script

路径请复制不要手打!

仍有错

最终

Windows环境下完整路径前加r!!!

executable_path=r"C:\Python27\Scripts\phantomjs-2.1.1-windows\bin\phantomjs.exe"

解决

4 0
原创粉丝点击