gpt4 book ai didi

python - 如何不使用默认配置文件启动 Chromedriver?

转载 作者:太空宇宙 更新时间:2023-11-03 18:09:46 25 4
gpt4 key购买 nike

我正在尝试使用 Chromedriver 和非默认配置文件加载 Chrome。
我正在使用这个Python代码:

opt = webdriver.ChromeOptions()
chromedriver = r"C:/chromedriver/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
opt.add_argument(r"user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data\Default_Selenium")
driver = webdriver.Chrome(opt)


但我收到以下错误:

Traceback (most recent call last):
File "C:\Users\user\workspace\dd\src\start.py", line 29, in <module>
main()
File "C:\Users\user\workspace\dd\src\start.py", line 20, in main
driver = webdriver.Chrome(opt)
File "C:\Python27\Lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriver\chrome\webdriver.py", line 59, in __init__
self.service.start()
File "C:\Python27\Lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriver\chrome\service.py", line 68, in start
and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path. Please download from http://chromedriver.storage.googleapis.com/index.html and read up at http://code.google.com/p/selenium/wiki/ChromeDriver'

我做错了什么?

最佳答案

chromedriver 可执行文件应在 PATH 环境变量中可用,或者通过 Chrome()<的 executable_path 参数显式设置:

driver = webdriver.Chrome(executable_path=r'C:/chromedriver/chromedriver.exe',
chrome_options=opt)

关于python - 如何不使用默认配置文件启动 Chromedriver?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26216853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com