安装selenium与ChromeDriver的方法及遇到的错误。
安装selenium与ChromeDriver的方法及遇到的错误
一、安装selenium
方法一:在pycharm中安装
在Pycharm页面中File -> Settings -> Project:Name -> Project Interpreter -> 点击绿色‘+’ -> 搜索selenium安装
可以在 中设置pip镜像。
- 清华:https://pypi.tuna.tsinghua.edu.cn/simple
- 阿里云:http://mirrors.aliyun.com/pypi/simple/
- 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
- 华中理工大学:http://pypi.hustunique.com/
- 山东理工大学:http://pypi.sdutlinux.org/
- 豆瓣:http://pypi.douban.com/simple/
方法二:在控制台安装
键盘win+R打开搜索框,输入cmd 打开控制台 -> 输入 pip install selenium 安装
可以在输入时添加 -i 'pip镜像网址' 如:pip install selenium -i http://mirrors.aliyun.com/pypi/simple/
二、下载及使用ChromeDriver
1、下载
官方网址:http://npm.taobao.org/mirrors/chromedriver/ 下载
注:必须根据当前chrome版本安装相应的版本的ChromeDriver
否则会报错:
selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreated has invalid 'context' {"auxData":{"frameId":"FBDDD78438129FCE59A700FE9C518C72","isDefault":true,"type":"default"},"id":1,"name":"","origin":"://"} (Session info: chrome=73.0.3683.86)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)
ChromeDriver支持的Chrome版本,具体参考:https://blog.csdn.net/Eric_yong/article/details/86636902
截止2020年5月11日,新增
ChromeDriver版本 | 支持的Chrome版本 |
---|---|
v2.46 | v71-73 |
2、使用
使用ChromeDriver需要将下载的文件,解压放到python目录下
PS:我没有设置环境变量,下面的报错提示,只将文件放到了指定目录下。(可能之前在别的项目里有过设置)
否则会报错:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36\Lib\subprocess.py", line 709, in __init__restore_signals, start_new_session)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36\Lib\subprocess.py", line 997, in _execute_child startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/PyCharm/python爬虫/20-05-11.py", line 3, in <module>
dricer = webdriver.Chrome()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
最后,完成整个selenium及ChromeDriver的安装
- selenium 安装与chromedriver安装的方法步骤
- selenium + ChromeDriver安装及使用方法
- selenium包的pip下载命令以及Chrome(谷歌)、Firefox(火狐)浏览器驱动GeckoDriver安装方法
- centos在selenium中使用Chromedriver时Permission denied,权限错误的解决方法
- web自动化_浏览器驱动chromedriver安装方法(适用RF框架/Selenium/Appium)
- Selenium遇到的问题2 下载了chromedriver,并放在Path目录下,还是显示错误
- 解决win7和win8的64位系统安装NetAdvantage时总是提示%SystemDriver%inetpub\wwwroot错误的方法
- 安装php遇到的错误解决方法集锦
- vue-cli搭建中遇到的chromedriver安装失败问题解决
- 安装SQL Server2005遇到的性能监视器计数器要求错误的解决方法
- PowerDesigner反向数据库时遇到[Microsoft][ODBC SQL Server Driver][SQL Server]无法预定义语句。SQLSTATE = 37错误解决方法
- 安装CAJViewer时遇到注册模块出现1904错误解决方法
- selenium3 webdriver启动火狐、chrome、edge、Safari浏览器的方法
- sysbench 安装过程中遇到的错误及解决方法
- 手动编译安装PHP遇到错误以及解决方法记录
- Ubuntu16.04 Selenium+python 环境搭建 Chromedriver安装
- openstack安装部署时遇到的错误记录及解决方法
- ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml) 用javascript在客户端删除某一个cookie键值对 input点击链接另一个页面,各种操作。 C# 往线程里传参数的方法总结 TCP/IP 协议 用C#+Selenium+ChromeDriver 生成我的咕咚跑步路线地图 (转)值得学习百度开源70+项目
- ubuntu下安装selenium以及chromedriver、geckodriver和phantomjs等驱动
- virtualbox 安装时Kernel driver not installed (rc=-1908) 错误的解决方法(1)