简体   繁体   English

问题是 selenium,python,编码初学者

[英]Problem is selenium, python, beginner in coding

I received this error when trying to run my code, let me know what I can do.尝试运行我的代码时收到此错误,请告诉我我能做什么。 If needed I'll post the full code here.如果需要,我会在这里发布完整的代码。

Traceback (most recent call last):
  File "C:\Users\hp\Desktop\FB\GUI.py", line 104, in <module>
    main()
  File "C:\Users\hp\Desktop\FB\GUI.py", line 65, in main
    driver = webdriver.Chrome(options=options)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site- 
packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
 File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
RemoteWebDriver.__init__(
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 268, in __init__
self.start_session(capabilities, browser_profile)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 359, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
self.error_handler.check_response(response)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.19042 x86_64)    

you need to install a chrome driver and tell selenium where to find it.您需要安装 chrome 驱动程序并告诉 selenium 在哪里可以找到它。 by either:通过以下任一方式:

  • updating your PATH更新你的 PATH
  • using executable_path when instantiating a new driver实例化新驱动程序时使用 executable_path

then install chrome and tell chrome driver where to find it.然后安装 chrome 并告诉 chrome 驱动程序在哪里可以找到它。

The message indicate that the chrome driver was either not installed or not found by Python code.该消息表明 chrome 驱动程序未安装或未通过 Python 代码找到。

Check the following link to setup chrome drivers:检查以下链接以设置 chrome 驱动程序:

https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

The best way is to download the binary from following link:最好的方法是从以下链接下载二进制文件:

https://sites.google.com/a/chromium.org/chromedriver/ https://sites.google.com/a/chromium.org/chromedriver/

Once done, you can identify the path to the driver present in the local directory like following:完成后,您可以识别本地目录中存在的驱动程序的路径,如下所示:

from selenium import webdriver from selenium.webdriver.chrome.options import Options从 selenium 导入 webdriver 从 selenium.webdriver.chrome.options 导入选项

options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
print("Chrome Browser Invoked")
driver.quit()

You do not have the driver installed for your browser, or the python code cannot find it.您没有为您的浏览器安装驱动程序,或者 python 代码找不到它。 On the official Selenium website you can find detailed instructions for installing the appropriate driver: https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/ .在官方 Selenium 网站上,您可以找到安装相应驱动程序的详细说明: https://www.selenium.dev/documentation/webdriver/getting_drivers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM