使用Selenium时ChromeDriver版本匹配及路径转义问题求助
Selenium爬虫问题解决方案
问题1:Chrome 119版本无对应ChromeDriver的解决办法
- 用WebDriverManager库自动管理驱动:无需手动下载,它会自动匹配当前Chrome版本并下载对应驱动,安装后直接在代码中调用。示例代码:
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) - 手动下载的话,可找Chrome官方的Chrome for Testing资源站,119版本的ChromeDriver已上线,直接下载对应平台的版本即可。
问题2:Unicode escape编码错误的解决办法
这个错误是因为路径里的反斜杠被Python当成了转义字符,三种解决方式任选其一:
- 用原始字符串:在路径前加
r,让Python不解析转义字符,示例:driver_path = r'C:\Users\xxx\chromedriver.exe' - 用双反斜杠:把单个反斜杠换成两个,示例:
driver_path = 'C:\\Users\\xxx\\chromedriver.exe' - 用正斜杠:将路径中的反斜杠替换为正斜杠,示例:
driver_path = 'C:/Users/xxx/chromedriver.exe'
内容的提问来源于stack exchange,提问作者Muhammad Azeem
相关产品推荐
相关产品推荐

