[英]Why can't selenium find the chrome driver?
I am following a tutorial on using selenium and python to make a web scraper for twitter, and I ran into this error.我正在学习使用 selenium 和 python 为 twitter 制作网络爬虫的教程,但我遇到了这个错误。
File "C:\Python34\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 81, 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
I went to the website specified in the error and downloaded the driver.我去了错误中指定的网站并下载了驱动程序。 Then I added it to path by going to System Properties > Advanced > Environment Variables > Path > New and added the exe file to path.
然后我通过转到“系统属性”>“高级”>“环境变量”>“路径”>“新建”将其添加到路径中,并将 exe 文件添加到路径中。 I tried again and i still got the error.
我再次尝试,但仍然出现错误。
If you take a look to your exception:如果你看看你的例外:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
At the indicated url , you can see the Getting started with ChromeDriver on Desktop (Windows, Mac, Linux) .在指定的 url 中,您可以看到桌面版 ChromeDriver 入门(Windows、Mac、Linux) 。
Where there is written:哪里有写:
Any of these steps should do the trick:
这些步骤中的任何一个都应该可以解决问题:
- include the ChromeDriver location in your PATH environment variable
在 PATH 环境变量中包含 ChromeDriver 位置
- (Java only) specify its location via the webdriver.chrome.driver system property (see sample below)
(仅限 Java)通过 webdriver.chrome.driver 系统属性指定其位置(参见下面的示例)
- (Python only) include the path to ChromeDriver when instantiating webdriver.Chrome (see sample below)
(仅限 Python)在实例化 webdriver.Chrome 时包含 ChromeDriver 的路径(参见下面的示例)
If you are not able to include your ChromeDriver location in your PATH environment variable, you could try with the third one option:如果您无法在 PATH 环境变量中包含 ChromeDriver 位置,则可以尝试使用第三个选项:
import time
from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
driver.get('http://www.google.com');
Another way is download and uzip chromedriver and put 'chromedriver.exe' in C:\\Python27\\Scripts and then you need not to provide the path of driver, just另一种方法是下载并 uzip chromedriver并将 'chromedriver.exe' 放在 C:\\Python27\\Scripts 中,然后您不需要提供驱动程序的路径,只需
driver= webdriver.Chrome()
will work会工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.