1.0.13 • Published 10 years ago

node-scraper v1.0.13

Weekly downloads
2
License
ISC
Repository
-
Last release
10 years ago

#node-scraper

A simple web scraping module.

  var scraper = new Scraper('http://www.urbandictionary.com');
  scraper.scrape().on('done', function(err, statusCode, content){
    if (err){
      console.error(err);
    }
    else {
      console.log(statusCode, content);
    }
  });

or if we want to be more precise

  var scraper = new Scraper('http://www.urbandictionary.com', {
    selectors: ['.word', '.meaning']
  });

  scraper.scrape().on('done', function(err, statusCode, content){
    if (err){
      console.error(err);
    }
    else {
      console.log(statusCode, content);
    }
  });

and if we also want the value of some attributes for a selected element, we can append the set of the desired attributes (in curly braces) to the selector.

  var scraper = new Scraper('http://www.urbandictionary.com', {
    selectors: ['.word{href}', '.meaning']
  });

  scraper.scrape().on('done', function(err, statusCode, content){
    if (err){
      console.error(err);
    }
    else {
      console.log(statusCode, content);
    }
  });

what the the output might look like:

[
  {
    "selector": ".word",
    "content": [
      {
        "html": "No pun intended",
        "attributes": {
          "href": "/define.php?term=No+pun+intended&defid=8320127"
        }
      },
      {
        "html": "hashtalk",
        "attributes": {
          "href": "/define.php?term=hashtalk&defid=8320335"
        }
      }
    ]
  },
  {
    "selector": ".meaning",
    "content": [
      {
        "html": " Pun intended. (and now acknowledged) "
      },
      {
        "html": " When hashtags are spoken out loud. "
      }
    ]
  }
]

tests

Have a look at the tests for more usage examples.

$ grunt test

docs

Or generate and read the docs.

$ grunt docs
1.0.13

10 years ago

1.0.12

10 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago