selenium 安装与 chromedriver安装

 

selenium 安装与 chromedriver安装

安装selenium

selenium能够直接能够用pip安装。html

pip install selenium

安装chromedriver

 下载

chromedriver的版本必定要与Chrome的版本一致,否则就不起做用。web

有两个下载地址:chrome

一、http://chromedriver.storage.googleapis.com/index.htmlnpm

二、https://npm.taobao.org/mirrors/chromedriver/api

固然,你首先须要查看你的Chrome版本,在浏览器中输入chrome://version/浏览器

例如个人版本是72.0.3626,因此下载测试

 配置

解压压缩包,找到chromedriver.exe复制到chrome的安装目录(其实也能够随便放一个文件夹)。复制chromedriver.exe文件的路径并加入到电脑的环境变量中去。具体的:ui

进入环境变量编辑界面,添加到用户变量便可,双击PATH,将你的文件位置(C:\Program Files (x86)\Google\Chrome\Application\)添加到后面。google

完成后在cmd下输入chromedriver验证是否安装成功:spa

 测试

未配置环境也能够,例如:

复制代码

from selenium import webdriver
import time

def main():
    chrome_driver = 'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe'  #chromedriver的文件位置
    b = webdriver.Chrome(executable_path = chrome_driver)
    b.get('https://www.google.com')
    time.sleep(5)
    b.quit()

if __name__ == '__main__':
    main()

复制代码

已配置环境变量时

复制代码

from selenium import webdriver
import time

def main():
    b = webdriver.Chrome()
    b.get('https://www.baidu.com')
    time.sleep(5)
    b.quit()

if __name__ == '__main__':
    main()

复制代码

若是运行时提示

极可能是chromedriver的版本不对(不要问我怎么知道的)。



参考连接:

一、https://blog.csdn.net/qq_41429288/article/details/80472064

二、https://www.cnblogs.com/LeslieForever/p/8317158.html

 

http://www.javashuo.com/article/p-oiogqyoq-cm.html

ChromeDriver Version    Chrome Version
83.0.4103.39    83
83.0.4103.14    83
81.0.4044.138    81
81.0.4044.69    81
81.0.4044.20    81
80.0.3987.106    80
80.0.3987.16    80
79.0.3945.36    79
79.0.3945.16    79
78.0.3904.105    78
78.0.3904.70    78
78.0.3904.11    78
77.0.3865.40    77
77.0.3865.10    77
76.0.3809.126    76
76.0.3809.68    76
76.0.3809.25    76
76.0.3809.12    76
75.0.3770.90    75
75.0.3770.8    75
74.0.3729.6    74
73.0.3683.68    73
72.0.3626.69    72
2.46    71-73
2.46    71-73
2.45    70-72
2.44    69-71
2.43    69-71
2.42    68-70
2.41    67-69
2.40    66-68
2.39    66-68
2.38    65-67
2.37    64-66
2.36    63-65
2.35    62-64



































ChromeDriver与Chrome版本对应参照表及ChromeDriver下载连接

相关文章
相关标签/搜索