Python selenium踩坑记

Python 2020-01-10 51 次浏览 次点赞

PyCharm抛出的错误(完整):
Traceback (most recent call last):
  File "D:/PycharmProjects/untitled/test.py", line 11, in <module>
    driver = webdriver.Chrome(executable_path=driver_path)
  File "C:\Users\19353\Anaconda3\envs\untitled\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\19353\Anaconda3\envs\untitled\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\19353\Anaconda3\envs\untitled\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\19353\Anaconda3\envs\untitled\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\19353\Anaconda3\envs\untitled\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 77
主要是这句:
This version of ChromeDriver only supports Chrome version 77
看出来没,意思是版本不支持

解决方法(chrome为例):
打开浏览器在地址栏输入:chrome://version/
得到浏览器的版本信息,如图例:

TIM图片20200110223355.png

查看版本对应的驱动:

点这查看!!!
TIM图片20200110223824.png

下载对应的驱动:

TIM图片20200110223938.png

解压后到一个文件夹里,记住文件夹路径,使用时如下图:
from selenium import webdriver

driver_path = r"D:\Software_installation_program\chromedriver\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(executable_path=driver_path)
问题总结:
我最开始以为chromedriver.exe是通用的,版本越高越能适配,结果发现我想多了,凉凉~

本文由 fmujie 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。

还不快抢沙发

添加新评论

召唤看板娘