简体   繁体   English

WebDriverException:消息:“chromedriver”可执行文件需要在 PATH 中,同时通过 Selenium Chromedriver python 设置 UserAgent

[英]WebDriverException: Message: 'chromedriver' executable needs to be in PATH while setting UserAgent through Selenium Chromedriver python

I'm a newbie in webscraping, I'm trying to modify my user agent using these lines :我是 webscraping 的新手,我正在尝试使用这些行修改我的用户代理:

from selenium import webdriver
chrome_path = r'C:\Users\Desktop\chromedriver_win32\chromedriver.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:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in startstdin=PIPE)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py",line 709, in __init__restore_signals, start_new_session)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py",line 997, in _execute_child startupinfo).
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\safia\AppData\Local\Programs\Python\Python36-32\Test 3- User Agent.py", line 9, in <module>
driver = webdriver.Chrome(chrome_options=options)
File "C:\Users\safia\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
self.service.start()
File "C:\Users\safia\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.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?你能帮我解决这个问题吗?

This error message...此错误消息...

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

...implies that the ChromeDriver was not found within the locations specified within PATH variable within Environment Variables . ...意味着ChromeDriver未在Environment VariablesPATH变量中指定的位置内找到。

Solution解决方案

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 :在初始化WebDriverWebBrowser时,您需要传递Key executable_path以及引用ChromeDriver的绝对路径的Value以及ChromeOptions对象作为参数,如下所示:

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:\Users\Desktop\chromedriver_win32\chromedriver.exe')
driver.get('https://www.google.co.in')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WebDriverException:WebDriverException:消息:“chromedriver”可执行文件需要在 PATH 中 - WebDriverException: WebDriverException: Message: 'chromedriver' executable needs to be in PATH selenium.common.exceptions.WebDriverException:消息:“chromedriver”可执行文件需要在 PATH 中 - selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH Selenium WebDriverException:消息:“ chromedriver.exe”可执行文件必须位于PATH中 - Selenium WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH WebDriverException:消息:“ ChromeDriver可执行文件需要在路径中可用 - WebDriverException: Message: 'ChromeDriver executable needs to be available in the path 为 Windows - selenium.common.exceptions.WebDriverException 安装 Chromedriver:消息:“chromedriver.exe”可执行文件需要在 PATH 中 - Installing Chromedriver for Windows - selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH WebDriverException 消息:'chromedriver' 可执行文件需要在 PATH 中(在 mac M1 上出错) - WebDriverException Message: 'chromedriver' executable needs to be in PATH ( Error on mac M1) selenium.common.exceptions.WebDriverException:消息:“chromedriver”可执行文件需要在无头 Chrome 的 PATH 错误中 - selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH error with Headless Chrome Python / Selenium - “chromedriver”可执行文件需要在路径中 - Python / Selenium - “chromedriver” executable needs to be in a PATH 'chromedriver' 可执行文件需要在 PATH 中 - Python - Selenium (MAC) - 'chromedriver' executable needs to be in PATH - Python - Selenium (MAC) 消息:在Web服务器上执行python硒时,&#39;chromedriver&#39;可执行文件需要位于PATH中 - Message: 'chromedriver' executable needs to be in PATH while executing python selenium on web server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM