Selenium使用Edge打开网页出现“你的连接不是专用连接xxx”解决方案

 当尝试访问的网站使用的是自签名的SSL证书或者没有使用SSL证书时出现“你的连接不是专用连接xxx”。这种情况经常发生在访问内网地址或开发环境时通过以下代码打开网站有时会出现。

可参考如下方法解决:

from selenium import webdriver
from selenium.webdriver.edge.options import Options
import time
# 初始化 Edge 浏览器选项
options = Options()

# 设置接受不受信任的SSL证书
capabilities = options.to_capabilities()
capabilities['acceptSslCerts'] = True
capabilities['acceptInsecureCerts'] = True

# 创建浏览器实例
driver = webdriver.Edge(capabilities=capabilities)

# 打开网页
driver.get('https://xxxxxx')

time.sleep(10)

# 关闭浏览器
driver.quit()

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用selenium的`attach_to_edge()`方法来连接已经打开Edge浏览器。具体步骤如下: 1. 首先需要导入selenium库: ```python from selenium import webdriver ``` 2. 打开Edge浏览器并获取其驱动程序: ```python driver = webdriver.Edge() ``` 3. 通过`session_id`和`executor_url`获取已经打开的浏览器实例: ```python session_id = driver.session_id executor_url = driver.command_executor._url driver.close() # 关闭当前打开的浏览器 ``` 4. 使用`attach_to_edge()`方法连接已经打开的浏览器: ```python driver = webdriver.Remote(command_executor=executor_url, desired_capabilities={}, options=options) driver.session_id = session_id ``` 其中,`options`是可选的,用于设置Edge浏览器的选项,例如设置启动时的页面大小、禁止加载图片等。 完整代码如下: ```python from selenium import webdriver # 打开Edge浏览器 driver = webdriver.Edge() # 获取session_id和executor_url session_id = driver.session_id executor_url = driver.command_executor._url # 关闭当前打开的浏览器 driver.close() # 连接已经打开的浏览器 options = webdriver.EdgeOptions() driver = webdriver.Remote(command_executor=executor_url, desired_capabilities={}, options=options) driver.session_id = session_id # 以连接状态使用Edge浏览器进行操作 driver.get('https://www.baidu.com') ``` 注意:使用`selenium attach_to_edge()`方法连接已经打开的浏览器时,浏览器版本与驱动程序版本必须匹配,否则可能会出现兼容性问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值