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

scrape-them-all

v2.0.0

Published

๐Ÿš€ An easy-to-handle Node.js scraper that allow you to scrape them all in a record time.

Downloads

27

Readme

Scrape-Them-All is a Cheerio layer which improves your scraping experience.

This package is recent, if you have any suggestions or you notice that something is not working, feel free to open an issue or a pull-request, we will be happy to answer them as soon as possible


๐Ÿ“ฆ Installation

# Using NPM
npm install --save scrape-them-all
npm install --save fetch-cookie #optional

# Using Yarn
yarn add scrape-them-all
yarn add fetch-cookie #optional

fetch-cookie is only required if you plan to use the cookieJar option on requests.

โš  If you get a too many redirects error when you scrape, we recommend to install fetch-cookie and use the option cookieJar: true in your request. You can also pass an instance of tough.CookieJar to this parameter.

Example:

scrapeTA({ url: 'https://google.com', cookieJar: true }, ...)

๐Ÿ“š Documentation

scrapeTA(query, schema)

Params:

  • query String or Object: The page url or the page url and node-fetch options.
  • schema Object: the list of elements to scrape and the corresponding HTML tags.

Returns:

  • Promise<Object>: A promise containing the result as JSON.

Schema options

| Option | Type | Description | | ------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | | selector | String or Object | Can be a string expression, DOM Element, array of DOM elements, or cheerio object. | | | trim | Boolean | Trim whitespaces in the result. Default as true. | | attribute | String | Return the value of the indicated attribute on the selected element. | | accessor | String or Function | Cheerio access method name (like html for returning html code) or a custom function that take a Cheerio instance as first parameter. | | transformer | Function | The first parameter is your current value for the selected item. Can return a Promise. | | listModel | Object | Contains the options stated above in case of a list. |

Example output

{
    "title": "An amazing game",
    "description": "<p>With an amazing description</p>",
    "image": "https://amazing.game/image.jpg",
    "price": 10.99,
    "users": [
        {
            "username": "Tanuki",
            "badges": [
                { "name": "An amazing player" },
                ...
            ]
        },
        ...
    ]
}

The code that goes with it

const { ScrapeTA } = require('scrape-them-all')
ScrapeTA('url_or_https_options', {
  title: '.header h1',
  description: {
    selector: '.header p',
    accessor: 'html',
    //  accessor: selected => selected.html(),
    trim: false
  },
  image: {
    selector: 'img',
    attribute: 'src'
  },
  price: {
    selector: '.footer #price',
    transformer: (value) => parseFloat(value)
  },
  users: {
    selector: '.body .users',
    listModel: {
      username: '.username',
      badges: {
        selector: '.badges',
        listModel: {
          name: '.badgeName'
        }
      }
    }
  }
})
  .then((data) => console.log(data))
  .catch((error) => console.error(error))

๐Ÿ’ช Contributions

TODO


๐Ÿ“œ License

MIT ยฉ Tanuki, Aperrix.