'phantomjs.exe' executable needs to be in PATH. (selenium PhantomJS python)

时间:2023-10-12 21:25:44

今天selenium PhantomJS python用了下,发现报错,提示我:'phantomjs.exe' executable needs to be in PATH.

from selenium import webdriver# Open PhantomJS
driver = webdriver.PhantomJS(executable_path='C:\phantomjs-2.1.1-windows\bin\phantomjs.exe')
这样运行报错,我百度了下,发现解决方式,在完整路径前面加了一个r 就行了
driver = webdriver.PhantomJS(executable_path=r'C:\phantomjs-2.1.1-windows\bin\phantomjs.exe')
# coding=utf-8
from selenium import webdriver
# Open PhantomJS
driver = webdriver.PhantomJS(executable_path=r'C:\phantomjs-2.1.1-windows\bin\phantomjs.exe')
driver.get("http://www.qq.com")
title = driver.title
driver.save_screenshot('qq.png')
print title #腾讯首页

'phantomjs.exe' executable needs to be in PATH. (selenium PhantomJS python)