使用Chrome,您可以在创建驱动程序时添加选项。你就这么做
options = Options()
options.headless = True
driver = webdriver.Chrome(PATH\TO\DRIVER, options=options)
但是由于某种原因,当试图对Microsoft做同样的事情时
options = Options()
options.headless = True
driver = webdriver.Edge(PATH\TO\DRIVER, options=options)
我知道这个错误
TypeError: __init__() got an unexpected keyword argument 'options'
出于某种原因,Edge的驱动程序不接受文件路径以外的任何其他参数。有没有办法运行边缘无头,并添加更多的选项,就像在Chrome?
发布于 2020-12-06 10:12:44
options = EdgeOptions()
options.use_chromium = True
options.add_argument("headless")
options.add_argument("disable-gpu")
尝试以上代码,您必须启用铬以启用无头。
https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=python
这只适用于新的边缘铬,而不是边缘遗留版本。在旧版本中,不支持“无头”。
全码
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
# make Edge headless
edge_options = EdgeOptions()
edge_options.use_chromium = True # if we miss this line, we can't make Edge headless
# A little different from Chrome cause we don't need two lines before 'headless' and 'disable-gpu'
edge_options.add_argument('headless')
edge_options.add_argument('disable-gpu')
driver = Edge(executable_path='youredgedriverpath', options=edge_options)
发布于 2021-03-21 12:42:22
webdriver.Edge
不接受任何options
,因此我将其转换为以下内容:它为我工作。
# imports
from selenium import webdriver
from msedge.selenium_tools import EdgeOptions
# options
options = EdgeOptions()
options.use_chromium = True
options.add_argument("--headless")
options.add_argument("disable-gpu")
browser = webdriver.Chrome(
executable_path="resources/msedgedriver.exe", options=options)
browser.get(gen_token)
我使用的Microsoft Edge版本是:
Microsoft Edge版本89.0.774.57 (正式构建)(64位)
这对我有用。
发布于 2021-05-28 05:41:10
用于边缘浏览器
options = EdgeOptions()
options.use_chromium = True
options.add_argument('--allow-running-insecure-content')
options.add_argument("--ignore-certificate-errors")
self.wd = webdriver.Chrome(executable_path=EdgeChromiumDriverManager().install(), options=options)
self.wd.maximize_window()
用于边缘无头
options = EdgeOptions()
options.use_chromium = True
options.add_argument("--headless")
options.add_argument("disable-gpu")
options.add_argument('--allow-running-insecure-content')
options.add_argument('--ignore-certificate-errors')
self.wd = webdriver.Chrome(executable_path=EdgeChromiumDriverManager().install(), options=options)
self.wd.maximize_window()
https://stackoverflow.com/questions/65171183
复制