selenium如何访问没有证书的网页

只需要在capabilities中加入"acceptInsecureCerts": True这个参数即可

capabilities = {
    'platform': operating_system,
    'browserName': browser_name,
    'version': version,
    "enableVNC": True,
    "screenResolution": screen_resolution,
    "labels": {
      "manual": "true"
    },
    "acceptInsecureCerts": True,
    'selenoid:options': {"env": env_proxy},
    # 'goog:chromeOptions': {'detach': True, 'extensions': [], 'args': [], 'w3c': False, "excludeSwitches": [ "enable-automation" ],
    #     "useAutomationExtension": False},
  }

  driver = webdriver.Remote(command_executor=url,
                            desired_capabilities=capabilities)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Selenium中,如果要打开需要选择证书网页,可以使用Firefox或Chrome浏览器,并在浏览器设置中指定默认证书。 对于Firefox浏览器,可以在安装目录下找到“cert8.db”文件,该文件包含默认证书。可以使用以下代码将其拷贝到Selenium使用的Firefox浏览器配置文件中: ``` from shutil import copyfile import os # Firefox profile directory profile = webdriver.FirefoxProfile('/path/to/firefox/profile') # Source certificate file cert_file = '/path/to/cert8.db' # Destination certificate file dest_cert_file = os.path.join(profile.path, 'cert8.db') # Copy certificate file to destination copyfile(cert_file, dest_cert_file) # Launch Firefox with profile driver = webdriver.Firefox(firefox_profile=profile) ``` 对于Chrome浏览器,可以在浏览器的高级设置中导入证书,并在Selenium中指定ChromeOptions以使用该证书。可以使用以下代码: ``` from selenium import webdriver # Path to the certificate file cert_file = '/path/to/cert.pfx' # Chrome options options = webdriver.ChromeOptions() # Add certificate to options options.add_argument('--auto-select-certificate-for-urls=https://example.com') options.add_argument('--certificate-file=%s' % cert_file) options.add_argument('--certificate-password=your_password') # Launch Chrome with options driver = webdriver.Chrome(chrome_options=options) ``` 在这里,`--auto-select-certificate-for-urls`选项指定需要选择证书的URL,`--certificate-file`选项指定证书文件的路径,`--certificate-password`选项指定证书密码。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值