Giter Site home page Giter Site logo

peremenov / seize Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 1.0 11.49 MB

Seize is light Node or Browser web-page content extractor inspired by arc90 readability and Safari Reader

JavaScript 0.95% HTML 99.05%
content-extraction dom text-score readability extract reader

seize's Introduction

seize

Build Status Dependency Status Codacy Badge


Seize is light Node or Browser web-page content extractor inspired by arc90 readability and Safari Reader.

Install

npm i --save seize

Usage

Seize can be used with DOM libraries such as jsdom for example. It only extracts and prepares certain DOM-node for further usage.

Example

var Seize = require('seize'),
    jsdom = require('jsdom').jsdom;

var window = jsdom('<your html here>').defaultView,
    seize  = new Seize(window.document);

seize.content(); // returns DOM-node
seize.text();    // returns only text

Browser usage

For browser usage you shoud clone you DOM object or create it from HTML string:

/**
 * Converts html string to Document
 * @param  {String} html  html document string
 * @return {Node}         document
 */
function HTMLParser(html){
  var doc = document.implementation.createHTMLDocument("example");
  doc.documentElement.innerHTML = html;
  return doc;
};

How it works

Here is algorythm how it works:

  • Getting html tags that we expect to be text or content container such as p, table, img, etc.
  • Filtering unnesessary tags by content and tag names wich defenantly can't be in a content container
  • Setting score for each container by containing tags
  • Setting score by class name, id name, tag xPath score and text score
  • Sorting canditates by score
  • Taking first candidate
  • Cleaning up article

Todo

Seize still in development, so you can use it at one's own risk. You always can help to improve it.

  • Improve readme
  • Improve text scoring
  • Improve page detection wich can't be extracted
  • More tests
  • More examples

Contributing

You are welcomed to improve this small piece of software :)

Author

seize's People

Contributors

peremenov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

autowds

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.