python - browser = webdriver.Chrome() 不起作用

标签 python selenium

我正在开始使用 Selenium for python 并有这个:

from selenium import webdriver
browser = webdriver.Chrome()

但是它给出了这个错误:

Traceback (most recent call last):
File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-
packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
 File "C:\Users\Bradley 
Jo\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in 
__init__
restore_signals, start_new_session)
File "C:\Users\Bradley 
Jo\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 997, in 
_execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
  File "C:\Users\Bradley Jo\Desktop\Project\app.py", line 3, in 
 <module>
 browser = webdriver.Chrome()
  File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-
  packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
 self.service.start()
 File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\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

[Finished in 1.0s]

有人知道如何解决这个问题吗?谢谢

最佳答案

对于 Windows:

  1. Check you have installed latest version of chrome browser
  2. If not, install latest version of chrome
  3. download the latest(or appropriate) version of chromedriver from here
  4. Paste the chromedriver.exe file in "<Install Dir>/Python27/Scripts" Folder.

下面的代码现在应该可以工作:

    from selenium import webdriver
    driver = webdriver.Chrome()

关于python - browser = webdriver.Chrome() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47640949/

相关文章:

python - 我如何打印除标题行之外的每个列表的第一个索引?

python - 确保 urlpatterns 是 path() 和/或 re_path() 实例的列表

java - 防止 Selenium WebDriver 在捕获异常后退出

google-chrome - Selenium - 未捕获的 WebDriverError : chrome not reachable

java - lang.NoClassDefFoundError : org/apache/http/impl/conn/PoolingClientConnectionManager htmlunit. HttpWebConnection.createHttpClient

html - 机器人框架,如何检查类

Python 和 ADNS,在某处陷入无限循环

Python从谷歌搜索结果页面获取所有链接

python - HTML 标签之间的 Selenium

python - 如何在Python中导入Azure BlobService?