这是我项目的一段代码
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
import time
def extract_data(self, usrname : str):
self.edge_options = Options()
self.edge_options.add_argument("--headless")
self.usrname = usrname
service = Service(executable_path=r'C:\web\msedgedriver.exe')
self.driver = webdriver.Edge(service=service)
self.driver.get(f'https://leetcode.com/{usrname}/')
我也使用 --headless open ,但浏览器窗口仍然打开,而不是仅在后台工作。 怎么解决?
self.driver = webdriver.Edge(service=service)
将上面更改为:
self.driver = webdriver.Edge(service=service, options=self.edge_options)