11
18

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 5 years have passed since last update.

PuppeteerでBasic認証されてるページにアクセス

Last updated at Posted at 2017-10-06

問題

example.png

解決

page.setExtraHTTPHeadersを使う。

const USERNAME = 'username';
const PASSWORD = 'password';

// Basic認証掛けられてるページのURL
const URL = 'https://...';

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setExtraHTTPHeaders({
    Authorization: `Basic ${new Buffer(`${USERNAME}:${PASSWORD}`).toString('base64')}`
  });
  await page.goto(URL);
})();

最初page.authenticate(#)使ってたけど、駄目だった。

11
18
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
11
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?