Mil*_*ano 9 python browser selenium phantomjs
我正在尝试在Python中运行PhantomJS驱动程序,但我收到错误.我已经读过,我应该把整条路径作为一个论点,但它没有帮助.
这是代码:
from selenium import webdriver
# driver = webdriver.Chrome('D:\Python_projects\chromedriver_win32/chromedriver.exe') # this works
driver = webdriver.PhantomJS(executable_path='D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "path to script", line 8, in <module>
driver = webdriver.PhantomJS(executable_path='D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')
File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 50, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 75, in start
raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver.
Screenshot: available via screen
Run Code Online (Sandbox Code Playgroud)
你知道我做错了什么吗?
小智 12
在原始字符串中创建路径,添加'r':
driver = webdriver.PhantomJS(executable_path=r'D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')
Run Code Online (Sandbox Code Playgroud)
Mal*_*imi 10
为简单起见,将可执行文件放在与脚本相同的目录中:
driver = webdriver.PhantomJS() # now there's no need for a path
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20432 次 |
| 最近记录: |