1

嗨,我尝试为基于 Chromium 的 Edge 驱动程序版本 90.0.818.42 运行以下代码:

from selenium import webdriver
from msedge.selenium_tools import EdgeOptions

dirpath = os.getcwd()

edge_driver_path_used = dirpath + r'/features/resources/drivers/msedgedriver.exe'

my_edge_option = EdgeOptions()
my_edge_option.use_chromium = True
my_edge_option.binary_location = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
edge_driver = webdriver.Edge(options=my_edge_option)

edge_driver.get('My URL Here')

运行此代码后,我收到以下异常:

edge_driver = webdriver.Edge(options=my_edge_option)
TypeError: __init__() got an unexpected keyword argument 'options'

我似乎没有错过任何导入,那为什么我会得到这个异常?请帮帮我

4

1 回答 1

2

似乎这是您问题的解决方案: 如何使用 Selenium Python 无头运行 Microsoft Edge?

  options = EdgeOptions()
  options.use_chromium = True

安装附加包,如:

pip install msedge-selenium-tools

并使用以下命令初始化驱动程序:

from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge

# Edge in headless mode
edge_options = EdgeOptions()
edge_options.use_chromium = True
driver = Edge(executable_path='your_driver_path', options=edge_options)

这是官方文档: https ://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=python

于 2021-04-21T09:20:09.667 回答