selenium 安装与chromedriver安装的方法步骤
安装
selenium可以直接可以用pip安装。
pip install selenium
chromedriver的安装一定要与Chrome的版本一致,不然就不起作用(不要问我是怎么知道的)。
有两个下载地址:
1、http://chromedriver.storage.googleapis.com/index.html
2、https://npm.taobao.org/mirrors/chromedriver/
或者本地下载https://www.jb51.net/softs/538241.html
当然,你首先需要查看你的Chrome版本,在浏览器中输入chrome://version/
例如我的版本是72.0.3626,所以下载
配置
解压压缩包,找到chromedriver.exe复制到chrome的安装目录(其实也可以随便放一个文件夹)。复制chromedriver.exe文件的路径并加入到电脑的环境变量中去。具体的:
进入环境变量编辑界面,添加到用户变量即可,双击PATH,将你的文件位置(C:\Program Files (x86)\Google\Chrome\Application\)添加到后面。
完成后在cmd下输入chromedriver验证是否安装成功:
测试
未配置环境也可以,例如:
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的版本不对(不要问我怎么知道的)。
参考链接:
1、https://www.jb51.nethttps://www.geek-share.com/detail/2771305306.html
2、https://www.jb51.nethttps://www.geek-share.com/detail/2771305614.html
以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
- web自动化_浏览器驱动chromedriver安装方法(适用RF框架/Selenium/Appium)
- selenium包的pip下载命令以及Chrome(谷歌)、Firefox(火狐)浏览器驱动GeckoDriver安装方法
- selenium 安装与 chromedriver安装
- selenium+chromedriver安装及简单使用
- mac 上安装selenium, phantomjs 和 chromedriver
- selenium3 webdriver启动火狐、chrome、edge、Safari浏览器的方法
- Selenium WebDriver(IE,Firefox,Chrome)安装
- 最简便安装python+selenium-webdriver环境方法
- 爬虫工具:虚拟机Selenium和PhantomJS,ChromeDriver 镜像安装教程
- windows+python3.5环境下安装selenium后无法导入webdriver的解决方法
- linux环境 安装chromedriver 和 phantomjs的方法
- selenium 安装与 chromedriver安装
- linux 安装 selenium 以及 chromedriver 安装
- selenium之关于 chromedriver的安装和使用
- weex 执行 npm install 时,chromedriver 和 phantomjs 安装失败的解决方法
- Ubuntu16.04 Selenium+python 环境搭建 Chromedriver安装
- selenium和chromedriver安装与基础应用
- selenium安装与配置,以及chromedriver的使用
- python+ubuntu+selenium安装chrome和chromedriver
- ubuntu下安装selenium以及chromedriver、geckodriver和phantomjs等驱动