[英]Problem is selenium, python, beginner in coding
尝试运行我的代码时收到此错误,请告诉我我能做什么。 如果需要,我会在这里发布完整的代码。
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)
您需要安装 chrome 驱动程序并告诉 selenium 在哪里可以找到它。 通过以下任一方式:
然后安装 chrome 并告诉 chrome 驱动程序在哪里可以找到它。
该消息表明 chrome 驱动程序未安装或未通过 Python 代码找到。
检查以下链接以设置 chrome 驱动程序:
https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
最好的方法是从以下链接下载二进制文件:
https://sites.google.com/a/chromium.org/chromedriver/
完成后,您可以识别本地目录中存在的驱动程序的路径,如下所示:
从 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()
您没有为您的浏览器安装驱动程序,或者 python 代码找不到它。 在官方 Selenium 网站上,您可以找到安装相应驱动程序的详细说明: https://www.selenium.dev/documentation/webdriver/getting_drivers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.