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

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

原文地址:https://www.cnblogs.com/lxs1314/p/8377582.html