报错:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
解决1:
driver = webdriver.Chrome(executable_path=""),实例化浏览器时需要填写executable_path
1、先打开chrome 输入 “chrome://version/”来查看chrome版本
2、访问 http://chromedriver.storage.googleapis.com/index.html 下载对应版本
3、把解压后的 chromedriver.exe 文件放入 python-lib-sitepackages-selenium-webdriver-chrome文件中
4、再把代码中的路径 修改成上面chromedriver.exe文件放入的路径 ,driver = webdriver.Chrome(executable_path="")
解决2:
driver = webdriver.Chrome() ,不需要填写executable_path,配置环境时,将chromdriver放到python安装文件下,会默认到$PATH下寻找
1、先打开chrome 输入 “chrome://version/”来查看chrome版本
2、访问 http://chromedriver.storage.googleapis.com/index.html 下载对应版本
3、把解压后的 chromedriver.exe 文件放入到相应位置,包括python和chrome安装位置
4、把chrome的安装目录添加到环境变量,电脑“设置”里面“高级系统设置”-“环境变量”-“用户变量”-“path”,将chromedriver.exe文件路径复制进去
报错:
E File "F:\gitlab\Auto\conftest.py", line 62
E driver = webdriver.Chrome(executable_path="C:\Users\ityw\Local\Programs\Python\Python39\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe")
E ^
E SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
解决方案:
在路径前面加r,即保持字符原始值的意思