【问题标题】:handshake failed; returned -1, SSL error code 1, net_error -201握手失败;返回 -1,SSL 错误代码 1,net_error -201
【发布时间】:2020-08-18 10:10:13
【问题描述】:

我正在尝试使用 python 使用 selenium 进行网络抓取,但每当我运行代码时,我都会得到 错误

[4824:524:0818/154954.605:ERROR:ssl_client_socket_impl.cc(959)] handshake failed; returned -1, SSL error code 1, net_error -201
[4824:524:0818/154954.614:ERROR:ssl_client_socket_impl.cc(959)] handshake failed; returned -1, SSL error code 1, net_error -201
[4824:524:0818/154954.721:ERROR:ssl_client_socket_impl.cc(959)] handshake failed; returned -1, SSL error code 1, net_error -201
[4824:524:0818/154954.730:ERROR:ssl_client_socket_impl.cc(959)] handshake failed; returned -1, SSL error code 1, net_error -201
Empty DataFrame
Columns: [Rank, Country, Total Cases, New Cases, Deaths, New Deaths, Recovered, Active Cases, Critical]
Index: []

我的代码我正在尝试使用 selenium 访问名为 worldometer 的网站,并使用 pandas 从他们网站上的表格中提取数据。我之前使用过 selenium 来访问其他网站,但它没有给出错误。我正在使用python 3.6.8版

我尝试了安装 OpenSSl 等修复,但没有安装 我还尝试了其他修复,例如添加 --ignore-certificate-errors 和 --ignore-ssl-errors 但这也不起作用

import pandas as pd
import time

# Covid 19 Webscraper

browser = webdriver.Chrome('C:\\webdrivers\\chromedriver.exe')

# opening sites

browser.get("https://www.worldometers.info/coronavirus/")
time.sleep(15)

#creating Data Frame

df = pd.DataFrame(columns=['Rank','Country','Total Cases','New Cases','Deaths','New Deaths','Recovered','Active Cases','Critical'])

# finding xpath and info

for i in browser.find_elements_by_xpath("//*[@id='main_table_countries_today']/tbody/tr"):
    td_list = i.find_elements_by_tag_name('td')
    row = []
    for td in td_list:
        row.append(td.text)
    data={}
    for j in range(len(df.columns)):
        data[df.columns[j]] = row[j]
    
    df.append(data, ignore_index=True)
print(df)

【问题讨论】:

  • 并非所有用户都可以访问屏幕截图。请将错误文本复制粘贴为代码并删除屏幕截图。

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


【解决方案1】:

您的浏览器商店似乎没有网站所需的证书。请使用以下 chrome 选项:

options = webdriver.ChromeOptions()
options.add_argument("--ignore-certificate-error")
options.add_argument("--ignore-ssl-errors")
browser = webdriver.Chrome('C:\\webdrivers\\chromedriver.exe',options=options)
browser.get("https://www.worldometers.info/coronavirus/")

具备能力:

caps = webdriver.DesiredCapabilities.CHROME.copy()
caps['acceptInsecureCerts'] = True
caps['acceptSslCerts'] = True
driver = webdriver.Chrome(desired_capabilities=caps)

【讨论】:

  • 有趣的是我没有收到任何错误并且使用相同的代码:P。您能否再次尝试更新答案(使用功能)。另请检查您的 python 和 chromedriver 版本。我分别使用的是 3.8.0 和 84.0.xxx。
  • 我也在使用相同的版本并运行两次更新的代码,但仍然报错
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-14
  • 2012-06-18
  • 1970-01-01
  • 2017-02-01
相关资源
最近更新 更多