相关疑难解决方法(0)

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

我是网络抓取的新手,我正在尝试使用以下几行修改我的用户代理:

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)
Run Code Online (Sandbox Code Playgroud)

环境变量中的路径没问题,但我一直收到此错误消息:

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__ …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver selenium-webdriver

6
推荐指数
1
解决办法
1万
查看次数

错误消息:“chromedriver”可执行文件需要位于 PATH 中

我刚刚开始使用 Selenium 并能够加载 google,但现在当我运行以下代码时会产生错误:

selenium.common.exceptions.WebDriverException: Message 'chromedriver' executable needs
to be PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Run Code Online (Sandbox Code Playgroud)

为什么说“C:Users/Colin/Python/chromedriver”不是路径?

from selenium import webdriver

browser = webdriver.Chrome("C:Users/Colin/Python/chromedriver")
browser.get('http://www.google.com')

browser.quit()
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver selenium-webdriver

2
推荐指数
1
解决办法
1万
查看次数