python+selenium+webdriver+chromedriver

今天用到selenimu中的webdriver,在安装外selenium后,输入以下程序出现错误:"' chromedriver' executable needs to be in PATH":
from selenium import webdriver
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe" #配置一下环境变量也可
driver= webdriver.Chrome(chromedriver)
driver.get('http://www.baidu.com') 
查资料后是因为:
1.没有下载对应的chromedriver程序,下载浏览器对应版本的chromedriver版本
附录:链接chromedriver和浏览器对应版本: https://sites.google.com/a/chromium.org/chromedriver/home

2.将chromedriver程序加在项目目录下或者配置相关的环境变量也可

同样对应pahntomjs模块也是这样,报错信息‘WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ’

对应下载phantomjs链接:http://phantomjs.org/download.html

也可以采用上述两种方法解决错误

browser=webdriver.PhantomJS(executable_path=r'C:\Users\lyh\Anaconda2\phantomjs-2.1.1-windows\bin\phantomjs.exe')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值