Giter Club home page Giter Club logo

node-readability's Introduction

Readability

Turn any web page into a clean view. This module is based on arc90's readability project.

Build Status

Features

  1. Optimized for more websites.
  2. Support encodings such as GBK and GB2312.
  3. Converts relative urls to absolute for images and links automatically(Thank Guillermo Baigorria & Tom Sutton).

Install

npm install node-readability

Usage

read(html [, options], callback)

Where

  • html url or html code.
  • options is an optional options object
  • callback is the callback to run - callback(error, article, meta)

Example

var read = require('node-readability');

read('http://howtonode.org/really-simple-file-uploads', function(err, article, meta) {
  // The main body of the page.
  console.log(article.content);
  // The title of the page.
  console.log(article.title);

  // The raw HTML code of the page
  console.log(article.html);
  // The document object of the page
  console.log(article.document);
  
  // The response object from request lib
  console.log(meta);
});

NB If the page has been marked with charset other than utf-8, it will be converted automatically. Charsets such as GBK, GB2312 is also supported.

Options

node-readability will pass the options to request directly. See request lib to view all available options.

node-readability has additional option cleanRules which allow set your own validation rule for tags. If true rule is valid, otherwise no. options.cleanRules = [callback(obj, tagName)]

read(url, {
        cleanRulers : [
          function(obj, tag) {
            if(tag === 'object') {
              if(obj.getAttribute('class') === 'BrightcoveExperience') {
                return true;
              }
            }
          }
        ]
      }, function(err, article, response) {});

article object

content

The article content of the web page. Return false if failed.

title

The article title of the web page. It's may not same to the text in the <title> tag.

html

The original html of the web page.

document

The document of the web page generated by jsdom. You can use it to access the DOM directly(for example, article.document.getElementById('main')).

meta object

response object from request lib. If you need to get current url after all redirect or get some headers it can be useful.

Contributors

https://github.com/luin/node-readability/graphs/contributors

License

This code is under the Apache License 2.0. http://www.apache.org/licenses/LICENSE-2.0

Bitdeli Badge

node-readability's People

Contributors

luin avatar pekhota avatar bitdeli-chef avatar btmills avatar brianmaissy avatar kopertop avatar gbaygon avatar rahar avatar buley avatar yanni4night avatar

Watchers

James Cloos avatar  avatar

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.