A small utility library for retrieving and scraping web content. It targets scraping content with a unique attribute id, class or tag.
Periodically I wind up writing scripts to screen scrape or spider sites. Node is really nice for this. extractor-js is a utility module for these types of script.
extractor has four methods -
fetchPage- get a page from the local file system or via http/https
scrape- A combination of FetchPage(), Cleaner(), and Transformer() which fetches the content, parses it via jsDOM/jQuery and extracting interesting parts based on the jQuery selectors pass to it creating an object with the same structure as the selector object and passing it to Scrape()'s callback method. You can override the Cleaner() and Transformer() methods by passing in your own cleaner and transformer functions.
spider- a utility implementation of Scrape using a fixed map for anchors, links, scripts and image tags.
This example script would process three pages from the pages array and output a console log of the processed page and a JSON representation of the content described by the selectors.
In this example we spider the homepage of the NodeJS website and list of the links found on the page.
var extractor = require'extractor';extractorspider''var i;if errconsole.error"ERROR: " + err;console.log"from -> "+ envpathname;console.log"data -> " + JSONstringifydata;fori = 0; i < datalinkslength; i += 1console.log"Link " + i + ": " + datalinksihref;;