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

webrobber

v0.2.0

Published

A light weight nodejs library to helps you grab the specified content on any web page on internet.

Downloads

8

Readme

WebRobber

WebRobber is a light weight nodejs library. Main goal of this library is to helps you grab the specified content on any web page on internet.

Example

Let's use http://www.google.com as a example. If you check the source code of the page , it should like below:

<html>
    <head>
        <title>google</title>
    </head>
    <body>
    ....
        <img src="/images/icons/product/chrome-48.png"/>
    ....
        <div>
            <img id="hplogo" src="'/images/srpr/logo9w.png'"/>
        </div>
    ....
    </body>
</html>

Now let's use WebRoober to grab the title of this page , url of the logo image and all the image urls.

var webRobber = require('webrobber');

var url = "http://www.google.com";
var dataMaps = {
        title:"title",
        logoImg:"#hplogo | src",
        images:"img | src"
        };

webRobber.grab(url, dataMaps, function (err, result) {
    if(err){
        console.log("Grab fail.");
    }else{
        console.log(result);
    }
});

The result will be :


{
  title: 'Google',
  logoImg: '/images/srpr/logo9w.png',
  images:  [
             '/images/icons/product/chrome-48.png',
             '/images/srpr/logo9w.png'
           ],
  _url: 'http://www.google.com'
}

To begin

Please make sure you have nodejs and npm installed.

  1. Install it:

    $ npm install webrobber --save
  2. Require it:

    var webRobber = require('webrobber');
    
  3. Prepare dataMap:

    var dataMap = { property name : selector [| attribute]}

    example:

    var dataMap = {
    			    title:"title",
    			    logoImg:"#hplogo | src"
       			};

    Please see DataMap for details

  4. Grab the content from web page

    webRobber.grab(url, dataMap, function (err, result) {
    	if(err){
       		console.log("Grab fail.");
    	}else{
        	console.log(result);
    	}
    });

    Or if you familiar with Promise (Q). You can do following:

    webRobber.grab(url, dataMap)
        .then(function(result){
            console.log(result);
        })
        .catch(function(error){
            console.log(error);
        });

DataMap

DataMap is a map object use to define Name and Selector of the content you want to grap. Name is used be mark the name of content in the final reslut object. Selector is used to select the content in the web page.

WebRobber's selector usage is nearly identical to Cheerio's and jQuery's. Please check Cheerio's selector

The default grabed value will be the .text() of a dom selected by selector. If you need grab attribute of a dom. Please add " | attribute name".

Example: we want to grab the src of a image dom

var dataMap = {
				logoImg:"#hplogo | src"
       	};

If you may have several possible selectors for one content. You can put all possible selectors in an array. All the selector will be checked one after another until we find valid content.

var dataMap = {
				logoImg:["#hplogo | src","#logo-url","#new-logo | src"]
       	};

If multiple contents are found for one selector. All contents will be set an array and saved in result. Please see example at top for you reference.

If use * as selector, all the content of web page will be save for the property.

Result

All the results of grabbing will be return in a object as result (Please see example at top for detail).

There is special value in result object : _url. It keeps the url used for grabbing.

Test

To run the tests for WebRobber, please run:

$ npm test

License

MIT © 2014 Eric Wu