Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Eagerod/html-cruncher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

html-cruncher

Build Status

html-cruncher is a light-weight, dependency-free package for parsing HTML documents. It was born out of the necessity to have an easy interface for finding certain elements in a page's DOM.

Usage

Start out by installing html-cruncher using npm:

npm install html-cruncher

Set up your node project to use the html-cruncher:

var request = require("request");
var HTMLElement = require("html-cruncher");

request("http://www.google.com", function(err, response, body) {
	var document = HTMLElement.fromString(body);
})

Features

Once you've gotten a parsed DOM, you can search against it using the same methods that you'd typically use in browser-side JavaScript.

  • getElementById
  • getElementsByClassName
  • getElementsByTagName

There's also a small subset of XPath available through the xpath method on HTMLElement. You can select elements in a DOM by providing some simple xpath commands:

  • Element selection, direct child and full DOM.
  • Predicates
    • Select node at index.
    • Only select text nodes.
    • Attribute equality.

More will be added as needs arise, but for now, this is all that's needed all uses of this package I've been informed of.