selenium的EDGE无头浏览器

from selenium import webdriver
from time import sleep
from selenium.webdriver.edge.options import Options

#edge_options = Options()
EDGE = {
    "browserName": "MicrosoftEdge",
    "version": "92.0.902.55",
    "platform": "WINDOWS",
    "ms:edgeOptions": {
        'extensions': [],
        'args': [
            '--headless',
            '--disable-gpu'
        ]}
}
bro = webdriver.Edge('./MicrosoftWebDriver.exe',capabilities=EDGE)
#浏览器无可视化界面
bro.get('https://www.baidu.com')

print(bro.page_source)
sleep(2)
bro.quit()
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
以下是使用 SeleniumEdge 浏览器模拟扫码登录的 Python 代码示例: ```python from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # 设置 Edge 浏览器的路径 edge_path = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" # 设置 EdgeOptions edge_options = webdriver.EdgeOptions() edge_options.use_chromium = True edge_options.add_argument("--headless") edge_options.add_argument("--disable-gpu") edge_options.add_argument("--disable-dev-shm-usage") edge_options.add_argument("--disable-extensions") edge_options.add_argument("--no-sandbox") edge_options.add_argument("--disable-browser-side-navigation") edge_options.add_argument("--disable-infobars") edge_options.add_argument("--disable-popup-blocking") edge_options.add_argument("--disable-default-apps") edge_options.add_argument("--disable-features=site-per-process") edge_options.add_argument("--disable-features=VizDisplayCompositor") edge_options.add_argument("--disable-features=RendererCodeIntegrity") edge_options.add_argument("--disable-features=NetworkServiceInProcess") edge_options.add_argument("--disable-features=NetworkService") # 创建 Edge 浏览器实例 driver = webdriver.Edge(executable_path=edge_path, options=edge_options) # 打开登录页面 driver.get("https://example.com/login") # 等待页面加载完成 wait = WebDriverWait(driver, 10) wait.until(EC.presence_of_element_located((By.ID, "qrcode"))) # 获取二维码元素 qrcode = driver.find_element_by_id("qrcode") # 鼠标悬停在二维码上,等待扫码登录 ActionChains(driver).move_to_element(qrcode).perform() # 等待登录成功 wait.until(EC.presence_of_element_located((By.CLASS_NAME, "success"))) # 获取登录成功后的页面标题 title = driver.title # 关闭浏览器 driver.quit() # 输出页面标题 print(title) ``` 希望能对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值