Skip to content
プロジェクト

website-scraper/website-scraper-puppeteer

GitHubで見る

概要

puppeteerを使って動的なウェブサイトのHTMLを返すwebsite-scraper用プラグイン

Web・アプリ開発

この数値の測り方

計測したスター増加

24時間
0
7日間
0
15日間
0
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

Version Downloads Node.js CI Code Coverage

website-scraper-puppeteer

Plugin for website-scraper which returns html for dynamic websites using puppeteer.

Sponsorship

Maintenance of this project is made possible by all the contributors and sponsors. If you'd like to sponsor this project and have your logo appear below click here 💖

Platinum sponsors

Byteful supplies ethical residential, mobile, ISP, and datacenter proxies, plus scraping and AI automation tools. Use code PUPPETSCRAPER10: 10% off residential proxies.
Power your website scraping projects with RapidProxy's 90M+ residential IPs across 195+ countries. Traffic never expires. Get 10% OFF with code RAPID10.

Sponsors

User avatar: Illia AntypenkoUser avatar: Pascal BirchlerUser avatar: Carlos RufoUser avatar: Francesca MaranoUser avatar: GitHubUser avatar: Andrew VorobiovUser avatar: User avatar: YusufUser avatar: Alex-BytefulUser avatar: Mescent Network Inc

Requirements

  • nodejs version >= 20
  • website-scraper version >= 6

Installation

npm install website-scraper website-scraper-puppeteer

Installing Chrome

Puppeteer normally downloads a compatible version of Chrome automatically during installation via a postinstall script. Starting with npm v12, lifecycle scripts (including postinstall) are disabled by default, so this automatic download no longer runs. You may then see an error like Could not find Chrome (ver. ...) when scraping.

If you use npm v12 or newer (or another package manager that blocks install scripts, e.g. recent pnpm), install Chrome manually after installing the packages:

npx puppeteer browsers install chrome

Alternatives:

  • Re-enable install scripts by adding puppeteer to the allowScripts field in your package.json (or .npmrc), so the browser is downloaded automatically again.
  • Use a Chrome/Chromium already installed on your system by pointing Puppeteer to it via launchOptions.executablePath (or the PUPPETEER_EXECUTABLE_PATH environment variable).

See Puppeteer's guide on why automatic downloads can be blocked for more details.

Usage

import scrape from 'website-scraper';
import PuppeteerPlugin from 'website-scraper-puppeteer';

await scrape({
    urls: ['https://www.instagram.com/gopro/'],
    directory: '/path/to/save',
    plugins: [ 
      new PuppeteerPlugin({
        launchOptions: { headless: true }, /* optional */
        gotoOptions: { waitUntil: "networkidle0" }, /* optional */
        scrollToBottom: { timeout: 10000, viewportN: 10 }, /* optional */
        exclusiveRendering: true, /* optional */
      })
    ]
});

Puppeteer plugin constructor accepts the following params:

  • launchOptions - (optional) - puppeteer launch options, can be found in puppeteer docs
  • gotoOptions - (optional) - puppeteer page.goto options, can be found in puppeteer docs
  • scrollToBottom - (optional) - in some cases, the page needs to be scrolled down to render its assets (lazyloading). Because some pages can be really endless, the scrolldown process can be interrupted before reaching the bottom when one or both of the limitations below are reached:
    • timeout - in milliseconds
    • viewportN - viewport height multiplier
  • exclusiveRendering - (optional, default true) - render pages one at a time and never while other requests are in flight, so cookies rotated by a page (see Cookies) are never presented stale. Set to false for websites which don't rotate cookies: pages are then rendered concurrently, which is considerably faster on large websites.

Cookies

Cookies passed in request.headers.Cookie (website-scraper option) are set into the browser's cookie jar for the scraped urls' hosts (including their subdomains), so pages opened in puppeteer send them too — but they are not leaked to other domains. This also applies when a scraped url redirects to a different host (e.g. example.com → shop.example.net): the redirect target does not receive the configured cookies unless its host is listed in urls. The jar is the source of truth afterwards: if the website rotates or refreshes cookies (via Set-Cookie, including on redirects, or js executed on the page), the updated cookies are used for all subsequent requests. To keep rotated cookies consistent, pages are rendered one at a time and never while other requests are in flight, regardless of requestConcurrency (see the exclusiveRendering option to disable this).

await scrape({
    urls: ['https://example.com/'],
    directory: '/path/to/save',
    request: {
        headers: { Cookie: 'session=abc123' }
    },
    plugins: [ new PuppeteerPlugin() ]
});

How it works

It starts Chromium in headless mode which just opens page and waits until page is loaded. It is far from ideal because probably you need to wait until some resource is loaded or click some button or log in. Currently this module doesn't support such functionality.

関連プロジェクトを探す

読み込み中…