Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dom-extractor

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-extractor

A remote HTML page DOM extractor. Extracts what you want from a remote page or a string, using selectors. Based on request for fetching, cheerios for parsing, cssom for checking css rules and juice for inlining css.

  • 0.0.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 17 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc