python2.7 - python selenium报PATH异常
本文介绍了python2.7 - python selenium报PATH异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
新手尝试第一次用selenium爬东西,但是第一步就卡住了
我的代码:
from bs4 import BeautifulSoup
from selenium import webdriver
import urllib
driver=webdriver.PhantomJS('C:\phantomjs-2.1.1-windows\bin\phantomjs.exe')
def search(keyword):
url_keyword=urllib.quote(keyword)
url="https://www.baidu.com/s?ie=UTF-8&wd="+keyword
print url
driver.get(url)
bsObj=BeautifulSoup(driver.page_source,"html5lib")
with open("temp.txt","w") as f:
f.write(bsObj.prettify().encode("utf-8"))
异常问题
我已经在路径当中加入了phantomjs的路径但是还是报这个问题很奇怪,问问大家有没有遇上这个情况的
下边是我打印的path环境变量的内容:
我的系统是window10六十四位 ,python版本是2.7.12,selenium是3.0.2
解决方案
你看看我这个就能理解了,跟aristotll是一个意思
另外第一次调试的话推荐用firefox (如果你是selenium 3.x需要下载一个geckodriver 驱动)
这篇关于python2.7 - python selenium报PATH异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文