Selenium/PhantomJS raises error

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

I'm trying to run PhantomJS driver in Python but I'm getting error. I've read that I should pass the whole path as an argument but it didn't help.

Here is the code:

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

ERROR:

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 

Do you know what am I doing wrong?

回答1:

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


回答2:

For simplicity's sake place the executable in the same directory as your script:

driver = webdriver.PhantomJS() # now there's no need for a path 


回答3:

For me none of the above solved the problem; I found the code:

driver = webdriver.PhantomJS() 

Will only work for root...



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!