Edge的启动方式与之前的启动有些差异
from selenium import webdriver from msedge.selenium_tools import EdgeOptions from msedge.selenium_tools import Edge def TransByEdge(): edge_options = EdgeOptions() edge_options.use_chromium = True # 设置无界面模式,也可以添加其它设置 # edge_options.add_argument('headless') # driver = Edge(options=edge_options) # edge_options = Options() prefs = { "translate": {"enabled": "true"}, "translate_whitelists": {"zh-CN": "en"} } edge_options.add_argument('--start-maximized') edge_options.add_argument( "--user-data-dir="+r"C:UsersAdministratorAppDataLocalMicrosoftEdgeUser Data") edge_options.add_experimental_option("prefs", prefs) edge_driver = r"F:Anaconda3msedgedriver.exe" # C:SoftwaresAnaconda3chromedriver.exe # chrome_driver = r"C:ProgramDataAnaconda3msedgedriver.exe" driver = Edge(options=edge_options, executable_path=edge_driver) # get直接返回,不再等待界面加载完成 desired_capabilities = DesiredCapabilities.EDGE desired_capabilities["pageLoadStrategy"] = "none" driver.get("https://weixin.sogou.com/") time.sleep(3) driver.close() driver.quit()
需要 msedgedriver.exe 下载 https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads
pip install msedge-selenium-tools
依赖参考 https://www.cnblogs.com/lixuelong/p/14451608.html