Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

python - Selenium/PhantomJS raises error

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_projectschromedriver_win32/chromedriver.exe') # this works
driver = webdriver.PhantomJS(executable_path='D:Pythonphantomjs-2.0.0-windowsinphantomjs.exe')

ERROR:

Traceback (most recent call last):
  File "path to script", line 8, in <module>
    driver = webdriver.PhantomJS(executable_path='D:Pythonphantomjs-2.0.0-windowsinphantomjs.exe')
  File "C:Python27libsite-packagesseleniumwebdriverphantomjswebdriver.py", line 50, in __init__
    self.service.start()
  File "C:Python27libsite-packagesseleniumwebdriverphantomjsservice.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Make the path in raw string, add 'r': 

driver = webdriver.PhantomJS(executable_path=r'D:Pythonphantomjs-2.0.0-windowsinphantomjs.exe')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...