Turning any web page into a clean view.
Turn any web page into a clean view. This module is based on arc90's readability project.
section) and Microdata API.
$ npm install node-readability
Note that as of our 2.0.0 release, this module only works with Node.js >= 2.0. In the meantime you are still welcome to install a release in the 1.x series(by
npm install node-readability@1) if you use an older Node.js version.
read(html [, options], callback)
callback(error, article, meta)
var read = require'node-readability';read''// Main Articleconsole.logarticlecontent;// Titleconsole.logarticletitle;// HTML Source Codeconsole.logarticlehtml;// DOMconsole.logarticledocument;// Response Object from Request Libconsole.logmeta;// Close article to clean up jsdom and prevent leaksarticleclose;;
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.
node-readability will pass the options to request directly. See request lib to view all available options.
node-readability has two additional options:
cleanRulerswhich allow set your own validation rule for tags.
If true rule is valid, otherwise no. options.cleanRulers = [callback(obj, tagName)]
readurlcleanRulers:iftag === 'object'ifobjgetAttribute'class' === 'BrightcoveExperience'return true;//...;
preprocesswhich should be a function to check or modify downloaded source before passing it to readability.
options.preprocess = callback(source, response, contentType, callback);
readurlif sourcelength > maxBodySizereturn callback'too big';callbacknull source;//...;
The article content of the web page. Return
false if failed.
The article title of the web page. It's may not same to the text in the
The original html of the web page.
The document of the web page generated by jsdom. You can use it to access the DOM directly(for example,
response object from request lib. If you need to get current url after all redirect or get some headers it can be useful.
This lib is using jsdom to parser HTML instead of cheerio because some data such as image size and element visibility isn't able to acquire when using cheerio, which will significantly affect the result.
This code is under the Apache License 2.0. http://www.apache.org/licenses/LICENSE-2.0