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

netscrape

v0.3.0

Published

A structural framework for creating good bots

Downloads

8

Readme

NetScrape

Web scraping for Node.js made efficient, simple, and compliant. NetScrape complies with the Robots Exclusion Protocol.

Installation

npm install netscrape

Usage

Netscrape is designed to be simple, but also extensible enough for advanced use cases. The following example demonstrates how to make a simple request to a website.

import Bot from 'netscrape';

const exampleBot = new Bot({ name: 'ExampleBot', version: '1.0' });

try {
  const response = await exampleBot.makeRequest('https://www.example.com/path');
  console.log(response.body);
} catch (error) {
  console.error(error);
}

Bot#constructor

import Bot from 'netscrape';

type BotOptions = {
  name: string;
  version: string;
  minimumRequestDelay?: number;
  maximumRequestDelay?: number;
  disableCaching?: boolean;
  policyURL?: string;
  hideLibraryAgent?: boolean;
  userAgent?: string;
};

const exampleBot = new Bot({
  name: 'ExampleBot' /* required, Name of your bot */,
  version: '1.0' /* required, Version of your bot */,
  minimumRequestDelay: 1000 /* optional, Minimum delay between requests in milliseconds */,
  maximumRequestDelay: 5000 /* optional, Maximum delay between requests in milliseconds (default 10000) */,
  disableCaching:
    true /* optional, Disable caching of responses (default false) */,
  policyURL:
    'https://www.example.com/robots.txt' /* optional, URL to robots.txt file (default https://npm.im/netscrape) */,
  hideLibraryAgent:
    true /* optional, Hide the library agent from the user agent (default false) */,
  userAgent:
    'ExampleBot/1.0' /* optional, Custom user agent, overrides all other user agent fields */,
});

Bot#makeRequest

import Bot from 'netscrape';

const exampleBot = new Bot({ name: 'ExampleBot', version: '1.0' });

try {
  /* Note: Bot#makeRequest automatically requests /robots.txt in the background */
  const response = await exampleBot.makeRequest(
    'https://www.example.com/path' /* required, well-formatted URL to make request to */,
    false /* optional, should you return a byte stream instead of utf8 text */,
  );

  /* Bot#makeRequest returns the raw npm.im/got package request response */
  console.log(response.body);
} catch (error) {
  /* Robots.txt rejection, robots.txt 500 error, etc. */
  console.error(error);
}

Bot#makeRequestWithBody

import Bot from 'netscrape';

const exampleBot = new Bot({ name: 'ExampleBot', version: '1.0' });

try {
  /* Note: Bot#makeRequestWithBody automatically requests /robots.txt in the background */
  /* Note: Bot#makeRequestWithBody automatically sets the
    Content-Type header to application/json or text/plain based on the body type */

  const response = await exampleBot.makeRequestWithBody(
    'https://www.example.com/path' /* required, well-formatted URL to make request to */,
    {
      example: 'body',
    } /* required, body to send to server (string or object) */,
    {
      'x-example-header': 'example header',
    } /* optional, headers to send to server */,
    'POST' /* optional, HTTP method to use (default POST) */,
  );

  /* Bot#makeRequestWithBody returns the raw npm.im/got package request response */
  console.log(response.body);
} catch (error) {
  /* Robots.txt rejection, robots.txt 500 error, etc. */
  console.error(error);
}

License

MIT (C) 2023 Russell Steadman. See LICENSE file. Visit Google deps.dev for dependency information.