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/
得到浏览器的版本信息,如图例:
查看版本对应的驱动:
点这查看!!!
下载对应的驱动:
解压后到一个文件夹里,记住文件夹路径,使用时如下图:
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是通用的,版本越高越能适配,结果发现我想多了,凉凉~
还不快抢沙发