WebDriverException: Message: #39;chromedriver#39; executable needs to be in PATH while setting UserAgent through Selenium Chromedriver python(WebDriverException:消息:“chromedriver可执行文件需要在 PATH 中,同时通过 Selenium Chromedriver python 设置 UserAgent) - IT屋-程序员软件开发技
问题描述
我是网络抓取的新手,我正在尝试使用以下代码来修改我的用户代理:
I'm a newbie in webscraping, I'm trying to modify my user agent using these lines :
from selenium import webdriver
chrome_path = r'C:UsersDesktopchromedriver_win32chromedriver.exe'
driver = webdriver.Chrome(chrome_path)
options = webdriver.ChromeOptions()
options.add_argument('user-agent = Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36')
driver = webdriver.Chrome(chrome_options=options)
环境变量中的路径没有问题,但我一直收到此错误消息:
The path in environment variable is ok but I keep having this error message:
File "C:UsersAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdrivercommonservice.py", line 76, in startstdin=PIPE)
File "C:UsersAppDataLocalProgramsPythonPython36-32libsubprocess.py",line 709, in __init__restore_signals, start_new_session)
File "C:UsersAppDataLocalProgramsPythonPython36-32libsubprocess.py",line 997, in _execute_child startupinfo).
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UserssafiaAppDataLocalProgramsPythonPython36-32Test 3- User Agent.py", line 9, in <module>
driver = webdriver.Chrome(chrome_options=options)
File "C:UserssafiaAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriverchromewebdriver.py", line 68, in __init__
self.service.start()
File "C:UserssafiaAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdrivercommonservice.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
你能帮我解决这个问题吗?
Can you please help me fix this issue?
推荐答案
这个错误信息...
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
...暗示 ChromeDriver 在 环境变量 内的 PATH 变量中指定的位置中找不到.
...implies that the ChromeDriver was not found within the locations specified within PATH variable within Environment Variables.
您需要传递 Key executable_path 以及 Value 引用 ChromeDriver 的绝对路径连同 ChromeOptions 对象作为参数,同时初始化 WebDriver 和 WebBrowser,如下所示:
You need to pass the Key executable_path along with the Value referring to the absolute path of the ChromeDriver along with the ChromeOptions object as an argument while initializing the WebDriver and WebBrowser as follows :
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('user-agent = Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:UsersDesktopchromedriver_win32chromedriver.exe')
driver.get('https://www.google.co.in')
这篇关于WebDriverException:消息:“chromedriver"可执行文件需要在 PATH 中,同时通过 Selenium Chromedriver python 设置 UserAgent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WebDriverException:消息:“chromedriver"可执行文件需要在 PATH 中,同时通过 Selenium Chromedriver python 设置 UserAgent


基础教程推荐
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 筛选NumPy数组 2022-01-01