Skip to content
프로젝트

website-scraper/website-scraper-puppeteer

GitHub에서 보기

소개

puppeteer를 사용해 동적 웹사이트의 HTML을 반환하는 website-scraper 플러그인

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

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.

관련 프로젝트 살펴보기

불러오는 중…