selenium报错
下了对应版本的webdriver,运行
from selenium import webdriver
driver = webdriver.Chrome()
报错
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
driver = webdriver.Chrome()
File "C:\Users\hasee\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\hasee\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\hasee\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\hasee\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\hasee\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
谷歌和eage都试了,环境变量也添加了,也放到python根目录了
求大神解答 1、‘unknown error:cannot find Chrome binary’:由于Chrome安装不是默认路径(直接拷贝安装文件),导致selenium找不到安装程序。
解决办法:①Chrome安装到默认路径。②setBinary方法设置程序路径。 我发个EDGE浏览器的
from msedge.selenium_tools import Edge, EdgeOptions
import json
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
MSEDGE_PATH = r"C:\Program Files (x86)\Microsoft\Edge Beta\Application\msedge.exe" #EDGE这个exe的位置(我是测试版)
MSEDGE_DRIVER_PATH = './msedgedriver.exe'#下载驱动https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
if __name__ == "__main__":
options = EdgeOptions()
options.use_chromium = True
options.binary_location = MSEDGE_PATH
options.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = Edge(options=options, executable_path=MSEDGE_DRIVER_PATH)
driver.execute_cdp_cmd(
"Page.addScriptToEvaluateOnNewDocument", {
"source":
"""
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
driver.get('https://fishc.com.cn/thread-183718-1-1.html') 驱动放哪里了,看错误貌似驱动没找到
页:
[1]