问题一:AttributeError: module 'selenium.webdriver' has no attribute 'Chromedriver'
配置selenium环境时,执行代码
from selenium import webdriver
driver = webdriver.Chromedriver() #driver = webdriver.Chromedriver(executable_path='C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe') driver.get('http:\www.baidu.com')
提示如下报错
E:code_studypythonpython_study_listvenvScriptspython.exe E:code_studypythonpython_study_list网络爬虫学习study_selenium_1.py Traceback (most recent call last): File "E:code_studypythonpython_study_list网络爬虫学习study_selenium_1.py", line 5, in <module> driver = webdriver.Chromedriver() AttributeError: module 'selenium.webdriver' has no attribute 'Chromedriver' Process finished with exit code 1
后来发现:
将如下代码:
driver = webdriver.Chromedriver()
替换为:
driver = webdriver.Chrome()
即可。
还需要注意的是,工作目录下不要存在与库相关的同名文件,建议修改。
问题二: 谷歌浏览器与chromedriver.exe不匹配的问题
网上有对应的版本和chromedriver的对应关系,需要说明的是,你下载的最新版本的谷歌(比如我下的77版本),其实际安装的版本是76版本。所以需要下载对应76的版本chromedriver.exe文件。