0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Python】プライバシーエラー'NET::ERR_CERT_DATE_INVALID'が表示されるサイトをWebスクレイピングする方法

Last updated at Posted at 2021-11-26

#概要

2021/10/1以降,古いMac環境 (OS X 10.11 El Capitan以前) やWindows 7以前にてWebサイトにアクセスした際,SSL証明書『Let's Encrypt』を利用したサイトにおいて以下の画像の様なSSL証明書のプライバシーエラーNET::ERR_CERT_DATE_INVALIDが表示されるようになった.

何らかの事情により古い環境でスクレイピングを行わなければならない場合,エラーが発生してしまうので対処法を記述する.

ssl_error.png

urllibを使用してWebスクレイピングする場合の対処法

スクリプト内に下記のコードを追記する.

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Seleniumを使用してWebスクレイピングする場合の対処法1

スクリプト内options.add_argument('--headless')の次の行に下記のコードを追記する.

# SSLエラーを許容するオプション
options.add_argument('--ignore-certificate-errors')

Seleniumを使用してWebスクレイピングする場合の対処法2 (スマートでないため非推奨)

スクリプト内driver.get(url)の次に行に下記のコードを追記する.

# エラー画面内のエラー文字列をXPathで取得
disp = driver.find_element(By.XPATH, '//*[@id="error-code"]').text
errcode = 'NET::ERR_CERT_DATE_INVALID'

# 強引にクリックしてエラー画面を突破
if disp == errcode:
    driver.find_element(By.XPATH, '//*[@id="details-button"]').click()
    driver.find_element(By.XPATH, '//*[@id="proceed-link"]').click()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?