0.0.14 • Published 9 years ago

dom-extractor v0.0.14

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

node-dom-extractor

Build Status Codacy Badge Dependency Status

A node package used to extract a DOM element from a remote page or a string, using selectors. Based on jsdom for fetching and parsing, and juice for inlining css.

Install

npm install dom-extractor

Extract DOM from a remote URL

var extractor = require('dom-extractor');
extractor.fetch("http://github.com/", "div.header", function(data){
	//data contains the extracted HTML with css inlined, here the github header
});

Extract DOM from a string

var extractor = require('dom-extractor');
extractor.fetch("<div class='a'>Hello</div><div class='b'>World</div>!", ".a", function(data){
	//should contains the div with class a
});

Note about # selector

When you use # as a selector, the browser do not send the data since it is a keyword for anchoring things in page, browser side.
To use it anyway, use |sharp| as the selector.

Using options

You can use options as the second parameter. List of current options are:

{
	selector: String, //set the selector for extraction default is body
	innerText: Boolean, //get text only from extraction, no html or css default is false
	inlineCss: Boolean //Put style in style attributes of extracted dom default is true
}

Example, using div.header selector and getting text only from result:

var extractor = require('dom-extractor');
extractor.fetch("http://github.com/", { selector: "div.header", innerText: true }, function(data){
	//data contains the extracted HTML with css inlined, here the github header
});

Use it as a middleware (Connect)

app.use('/proxy', extractor.middleware());

Running tests

npm install
npm install -g jshint
npm test
0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago