python爬虫学习笔记 3.#(番外) (selenium和chromedriver使用中得问题)

python爬虫学习笔记 3.#(番外) (selenium和chromedriver使用中得问题)

python爬虫学习笔记 1.1(通用爬虫和聚焦爬虫)
python爬虫学习笔记 1.2 ( HTTP和HTTPS )
python爬虫学习笔记 1.3 str和bytes的区别
python爬虫学习笔记 1.4 (Request简单使用)request安装
python爬虫学习笔记 1.5 (Requests深入)
python爬虫学习笔记 1.6 (HTTP/HTTPS抓包工具-Fiddler)
python爬虫学习笔记 1.7 (urllib模块的基本使用)
python爬虫学习笔记 1.8 (urllib:get请求和post请求)
python爬虫学习笔记 1.9 (Handler处理器 和 自定义Opener)
python爬虫学习笔记 2 (非结构化数据和结构化数据提取)
python爬虫学习笔记 2.1 (正则表达式re模块)
python爬虫学习笔记 2.2 (使用正则表达式得爬虫得简单案例)
python爬虫学习笔记 2.3 (XPath与lxml类库)
python爬虫学习笔记 2.4 (使用Xpath得案例)
python爬虫学习笔记 2.5 (json与JsonPath)
python爬虫学习笔记 2.6 (糗事百科案例)
python爬虫学习笔记 2.7 (多线程爬虫案例(初步了解))
python爬虫学习笔记 2.8 (beautifulsoup4)
python爬虫学习笔记 2.9 (使用bs4得案例)
python爬虫学习笔记 3 (动态HTML处理和机器图像识别)
python爬虫学习笔记 3.1 (动态HTML介绍)
python爬虫学习笔记 3.2 (Selenium与PhantomJS)
python爬虫学习笔记 3.#(番外) (selenium和chromedriver使用中得问题)

问题1:selenium安装,

解决本人使用Pycharm,anoconda,安装时pip失败,直接在setting中找到
在这里插入图片描述
install就行了

问题2:chromedriver安装

解决:
chromedriver的版本一定要与Chrome的版本一致,不然就不起作用。

有两个下载地址:

1、http://chromedriver.storage.googleapis.com/index.html

2、https://npm.taobao.org/mirrors/chromedriver/
当然,你首先需要查看你的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的版本不对(不要问我怎么知道的)。
参考博文:参考https://www.cnblogs.com/lfri/p/10542797.html

重点再提醒一下,版本一定要对应!!!!!

然而。。还是有错

from selenium import webdriver

browser = webdriver.Chrome()

browser.quit()

Traceback (most recent call last):

File “D:\Python36\lib\site-packages\selenium\webdriver\common\service.py”, line 76, in start

stdin=PIPE)

File “D:\Python36\lib\subprocess.py”, line 709, in init

restore_signals, start_new_session)

File “D:\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:/PycharmProjects/chapter11/seleniumExample.py”, line 2, in

browser = webdriver.Chrome()

File “D:\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py”, line 68, in init

self.service.start()

File “D:\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

Process finished with exit code 1

根据错误提示:Message: ‘chromedriver’ executable needs to be in PATH我们可以找到原因所在:chromedriver需要放在python安装路径下。

**

所以要把chromedriver放到python安装路径下就可以了,不要放到chrome安装目录下,没有起作用

**

可以从下面下载chromedriver,不同chrome版本,要下载不同chromedriver的版本,要注意对应呀

下面是chromedriver下载的路径,请放心下载使用

http://chromedriver.storage.googleapis.com/index.html

参考博文:https://blog.csdn.net/seeol/article/details/92829728

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值