npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mihnea.dev/webscraper

v1.0.6

Published

A robust web scraping library using Playwright for Node.js. This library provides an easy-to-use API for automating web interactions, extracting data, and handling various web scraping tasks efficiently.

Downloads

28

Readme

Web Scraper

A TypeScript-based web scraper that utilizes the Playwright library for performing automated web scraping tasks. This scraper is designed to be flexible, with customizable configurations, and is capable of handling various browser types and proxy settings. Additionally, it integrates with Browserless, a headless browser service, to enable remote browser automation.

Features

  • Supports Multiple Browser Types: Choose between Chromium, Firefox, and WebKit for scraping tasks.
  • Proxy Integration: Easily configure HTTP or SOCKS proxies for your scraping tasks.
  • Resource Blocking: Block specific resource types (e.g., images, media) to speed up scraping.
  • Headless and Stealth Modes: Run the browser in headless mode and enable stealth settings to avoid detection.
  • Custom JavaScript Execution: Inject and execute custom JavaScript on the page.
  • Screenshot Capture: Capture full-page screenshots of the web page.
  • Timeout and Wait Options: Customize timeouts, wait for specific events or elements before proceeding.

Installation

To install the web scraper, you can use npm or yarn:

npm install @mihnea.dev/webscraper

Configuration

The scraper can be configured with various options to customize its behavior. Here is an example configuration:

const config: IScraperConfig = {
    url:            "https://example.com",
    proxy_type:     ProxyType.Datacenter,
    browser_type:   BrowserType.Chromium,
    headless:       "true",
    block_ads:      "true",
    stealth:        "true",
    timeout:        30000,
    wait_until:     "networkidle",
};

Environment Variables

The scraper uses environment variables to configure proxy settings:

  • PROXY_[TYPE]_SERVER - Proxy server URL.
  • PROXY_[TYPE]_USERNAME - Proxy username (if required).
  • PROXY_[TYPE]_PASSWORD - Proxy password (if required).
  • PROXY_[TYPE]_BYPASS - Domains to bypass the proxy.

Replace [TYPE] with the proxy type, such as DATACENTER or MOBILE.

Usage

To use the web scraper, you can create a new instance of the Scraper class and call the scrape method:

import Scraper, { type IScraperConfig, ProxyType, BrowserType } from "@mihnea.dev/webscraper";

const config: IScraperConfig = {
    url:            "https://api.ipify.org",
    proxy_type:     ProxyType.None,
    browser_type:   BrowserType.Chromium,
    headless:       true,
    block_ads:      true,
    stealth:        true,
    timeout:        30000,
    wait_until:     "networkidle",
};

const scraper: Scraper = new Scraper(config);

scraper.run().then((result) => {
    console.log(result);
}).catch((error: Error) => {
    console.error("Scraping failed:", error.message);
});

IMPORTANT Currently, the Scraper class is designed to integrate with Browserless. To use the scraper with Browserless, you need to:

  • set BROWSER_WS_ENDPOINT environment variable to the Browserless WebSocket URL (defaults to ws://localhost:3000)
  • run the Browserless service locally or use the Browserless API. To run it locally, you can use the following Docker command:
docker run -p 3000:3000 ghcr.io/browserless/multi:latest

Contributing

Contributions are welcome! For feature requests, bug reports, or other feedback, please open an issue on GitHub. If you would like to contribute code, please submit a pull request.

License

This project is licensed under the SSPL-1.0 License. See the LICENSE file for details.