您的位置:首页 > 编程语言 > Python开发

Chrome driver 安装及问题

2017-07-04 14:05 716 查看
chrome driver

模拟浏览器对网站进行请求。
安装
chromedriver下载地址:https://sites.google.com/a/chromium.org/chromedriver/downloads
注:chrome版本

解压得到chromedriver.exe文件
将解压后的exe文件放到chrome的安装目录下...\Google\Chrome\Application\ (我的Chrome安装目录: C:\Program Files (x86)\Google\Chrome\Application )根据自己的chrome浏览器的路径
配置环境变量:
设置path环境变量,把chrome的安装目录添加至环境变量(chromedriver.exe不要加入路径)
测试:

#coding:utf-8

from selenium import webdriver

import time

def main():

b=webdriver.Chrome()

b.get('http://www.baidu.com')

time.sleep(5)

b.quit()

if __name__ == '__main__':

main()

问题:
出现selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.

提示chrome driver没有放置在正确的路径下,于是下载chrome dirver,然后放置到chrome所在的目录下,再次运行就OK了!

用下面这种方式检验是路径错误还是安装错误:
import os

from selenium import webdriver

chromedriver = "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"

driver = webdriver.Firefox()

driver.get('http://stackoverflow.com')

driver.quit()
执行没有问题,说明环境变量配置错误,那就重新返回上面配置吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python