12
8

More than 5 years have passed since last update.

Puppeteerでオレオレ証明書(自己署名証明書)のWebページにアクセスする

Last updated at Posted at 2018-04-06

はじめに

タイトルのとおりです。
Puppeteerのバージョンはv1.2で確認しています。

テストする

設定前

まず通常のPuppeteer起動の処理を書いてみます。

script.js
const url = 'https://[オレオレ証明書のページ]'

async () => {
  const browser = await puppeteer.launch({
    args: [
      '--no-sandbox',
      '--disable-setuid-sandbox',
    ]
  });

  const page = await browser.newPage();
  await page.goto(url);

     ・
     ・
    処理
     ・
     ・
})();

これを起動すると

(node:39231) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: net::ERR_CERT_AUTHORITY_INVALID at https://[オレオレ証明書のページ]
(node:39231) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

とエラーが出ます

設定後

追加するのは一行だけです。

script.js
const url = 'https://[オレオレ証明書のページ]'

async () => {
  const browser = await puppeteer.launch({
    ignoreHTTPSErrors: true, // ←ここだけ追加しました。
    args: [
      '--no-sandbox',
      '--disable-setuid-sandbox',
    ]
  });

  const page = await browser.newPage();
  await page.goto(url);

     ・
     ・
    処理
     ・
     ・
})();

と、以下の設定を入れてやるだけです。

ignoreHTTPSErrors: true,

これでオレオレ証明書ページもテストなりスクレイピングなりできますね。

それでは、よいPuppeteerライフをお過ごしください。

12
8
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
12
8