新手尝试第一次用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 驱动)