Selenium / 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')

错误:

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

你知道我在做什么错吗?

回答:

用原始字符串创建路径,并添加“ r”:

driver = webdriver.PhantomJS(executable_path=r'D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')

以上是 Selenium / PhantomJS引发错误 的全部内容, 来源链接: utcz.com/qa/413953.html

回到顶部