【问题标题】:How to avoid SSL certification error in Selenium Webdriver using Python?如何使用 Python 避免 Selenium Webdriver 中的 SSL 认证错误?
【发布时间】:2020-01-21 06:24:13
【问题描述】:

这是一个简单的 Python 代码,用于访问特定网站:

import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.webdriver.common.by import By
import time

profile=webdriver.ChromeOptions()
profile.add_argument('--ignore-certificate-errors')
driver =webdriver.Chrome(r'C:\Utility_Tools\WebDriver\chromedriver.exe')
driver.get('www.google.com')

但是由于我没有输入网址,所以它会引发错误。而如果我使用这个语句:

driver.get('https://www.google.com/')

错误消失。 由于我的数据库包含没有 SSL 认证的网站,有没有办法只浏览它们? 这是我的尝试,但这也失败了:

profile=webdriver.ChromeOptions()
profile.add_argument('--ignore-certificate-errors')
driver =webdriver.Chrome(r'C:\Utility_Tools\WebDriver\chromedriver.exe',options=profile)
driver.get('www.google.com')

我每次运行代码时触发的错误如下图所示:

errorhandler.py",第 242 行,在 check_response 中 raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidArgumentException: Message: invalid 参数(会话信息:chrome=79.0.3945.130)

【问题讨论】:

  • 请注意,当我使用带有正确SSL认证链接的网页时,错误消失了。
  • 所以它会抛出错误。 什么错误?始终包含整个错误消息。
  • 我不知道你在做什么,但 --disable-web-security 有时会让这些消失
  • 在@AMC结尾提到了错误。
  • 嗨@pguardiario,答案解决了我的问题。

标签: python selenium-webdriver web-scraping selenium-chromedriver


【解决方案1】:

问题出在get()www.google.com 不是有效的网址。如果不安全,您可以使用http 而不是https

driver.get('http://www.google.com')

【讨论】:

  • 实际上它与https一起使用。我想知道的是,由于我所有的网站都没有 http 标签,那么我如何在不指定 http 认证的情况下找出浏览方式。
  • @ShivamSahil 所有网站都有httphttps,否则它不是有效的网址。如果您在没有它的情况下存储 url,只需将其添加到代码中 'http://' + 'www.google.com'
  • @ShivamSahil 是的。
  • @ShivamSahil 所以即使它有 https,它仍然可以工作吗? 确保您了解问题所在,https 本身与它无关。
  • @AMC 实际上我的问题是没有 SSL 认证,selenium 无法正常工作,错误如上所示。所以我需要知道是否有直接使用 SSL 认证的方法。我了解 https 没有特定的作用。谢谢。
猜你喜欢
  • 2020-07-31
  • 1970-01-01
  • 2016-07-09
  • 1970-01-01
  • 1970-01-01
  • 2017-02-23
  • 1970-01-01
  • 1970-01-01
  • 2017-04-11
相关资源
最近更新 更多