1

我正在尝试使用 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' 

我究竟做错了什么?

4

1 回答 1

1

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

driver = webdriver.Chrome(executable_path=r'C:/chromedriver/chromedriver.exe',
                          chrome_options=opt)
于 2014-10-06T13:09:34.880 回答