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

@petitchevalroux/semantic-scraper

v2.0.0

Published

NodeJS html/xml scraper for extracting structured data from websites

Downloads

2

Readme

node-semantic-scraper

NodeJS html/xml scraper for extracting structured data from websites

Todo

  • Move transform function from cheerio-extractors
  • Improve code coverage

Install

npm install --save "@petitchevalroux/semantic-scraper"

Sample spider extracting articles from a website

Code

var scraper = require("@petitchevalroux/semantic-scraper");
var RegexSpider = scraper.RegexSpider;
var Crawler = scraper.Crawler;
var util = require("util");
var process = require("process");

var regexes = [];
regexes.push(
    new RegExp("^https?://dev.petitchevalroux.net/index(\..*?|)\.html")
);
var mapping = [];
// Extract all articles
mapping.push({
    "type": "articles",
    "selector": "table.contents h5 a",
    "properties": {
        "url": {
            "from": "attribute",
            "name": "href"
        },
        "title": {
            "from": "text"
        }
    }
});

function SampleSpider() {
    RegexSpider.call(
        this,
        // Start Url
        "http://dev.petitchevalroux.net/index.html",
        // Regexes matching urls to extract links from
        regexes,
        // Regexes matching urls to extract data from
        regexes,
        mapping
    );
}
util.inherits(SampleSpider, RegexSpider);

var crawler = new Crawler();
crawler.write(new SampleSpider());
crawler
    .on("data", function(data) {
        process.stdout.write("data:" + JSON.stringify(data, null, 2)+"\n");
    })
    .on("error", function(error) {
        process.stdout.write("error:" + JSON.stringify(error, null, 2)+"\n");
    });

Output

data:{
  "url": "http://dev.petitchevalroux.net/index.html",
  "items": {
    "articles": [
      {
        "url": "/php/passer-une-variable-environnement-php-via-php-fpm.408.html",
        "title": "Passer une variable d'environnement à php via php-fpm"
      },
      {
        "url": "/linux/docker-elk-redis-premiere-installation-linux.407.html",
        "title": "Docker, Elk et Redis, première installation"
      },
      {
        "url": "/mysql/comment-sauvegarder-votre-mot-passe-mysql-mysql.406.html",
        "title": "Comment sauvegarder votre mot de passe mysql"
      },
      {
        "url": "/linux/wheezy-impossible-ajouter-vpn-linux.405.html",
        "title": "Wheezy : Impossible d'ajouter un VPN "
      },
      {
        "url": "/hebergement/comparatif-vps-2013-test.404.html",
        "title": "Comparatif VPS 2013 : Le test"
      },
      {
        "url": "/hebergement/test-vps-pulseheberg.403.html",
        "title": "Test du VPS Pulseheberg"
      },
      {
        "url": "/hebergement/test-vps-be1host.402.html",
        "title": "Test du VPS Be1Host"
      },
      {
        "url": "/hebergement/test-vps-ikoula-flexicloud-2013.401.html",
        "title": "Test du VPS Ikoula Flexicloud 2013"
      },
      {
        "url": "/hebergement/test-vps-firstheberg-2013.400.html",
        "title": "Test VPS Firstheberg 2013"
      },
      {
        "url": "/hebergement/test-vps-ovh-2013.399.html",
        "title": "Test du VPS OVH 2013"
      }
    ]
  }
}