gpt4 book ai didi

python - Selenium/PhantomJS 引发错误

转载 作者:太空狗 更新时间:2023-10-29 19:34:08 26 4
gpt4 key购买 nike

我试图在 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')

错误:

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

关于python - Selenium/PhantomJS 引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29869757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com