Socket
Socket
Sign inDemoInstall

horseman-article-parser

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

horseman-article-parser

Web Page Inspection Tool. Sentiment Analysis, Keyword Extraction, Named Entity Recognition & Spell Check


Version published
Weekly downloads
11
increased by120%
Maintainers
1
Weekly downloads
 
Created
Source

Horseman Article Parser

A web page article parser which returns an object containing the article's formatted text and other attributes including sentiment, keyphrases, people, places, organisations, spelling suggestions, in-article links, meta data & lighthouse audit results.

Prerequisites

Node.js & NPM

Install

npm install horseman-article-parser --save

Usage Example

var parser = require('horseman-article-parser');

var options = {
  url: "https://www.theguardian.com/politics/2018/sep/24/theresa-may-calls-for-immigration-based-on-skills-and-wealth",
  lighthouse: {
    enabled: true
  }
}

parser.parseArticle(options)
  .then(function (article) {

    var response = {
      title: article.title.text,
      excerpt: article.excerpt,
      metadescription: article.meta.description.text,
      url: article.url,
      sentiment: { score: article.sentiment.score, comparative: article.sentiment.comparative },
      keyphrases: article.processed.keyphrases,
      keywords: article.processed.keywords,
      people: article.people,
      orgs: article.orgs,
      places: article.places,
      text: {
        raw: article.processed.text.raw,
        formatted: article.processed.text.formatted,
        html: article.processed.text.html
      },
      spelling: article.spelling,
      meta: article.meta,
      links: article.links,
      lighthouse: article.lighthouse
    }

    console.log(response);
  })
  .catch(function (error) {
    console.log(error.message)
    console.log(error.stack);
  })

parseArticle(options, <socket>) accepts an optional socket for pipeing the response object, status messages and errors to a front end UI.

See horseman-article-parser-ui as an example.

Options

The options below are set by default

var options = {
  userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
  // puppeteer options (https://github.com/GoogleChrome/puppeteer)
  puppeteer: {
    headless: true,
    defaultViewport: null,
  },
  // clean-html options (https://ghub.io/clean-html)
  cleanhtml: {
    'add-remove-tags': ['blockquote', 'span'],
    'remove-empty-tags': ['span'],
    'replace-nbsp': true
  },
  // html-to-text options (https://ghub.io/html-to-text)
  htmltotext: {
    wordwrap: 100,
    noLinkBrackets: true,
    ignoreHref: true,
    tables: true,
    uppercaseHeadings: true
  },
  // retext-keywords options (https://ghub.io/retext-keywords)
  retextkeywords: { maximum: 10 },
  // lighthouse options (https://github.com/GoogleChrome/lighthouse)
  lighthouse: {
    enabled: false
  }
}

For more Puppeteer launch options see https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions

At a minimum you should pass a url

var options = {
  url: "https://www.theguardian.com/politics/2018/sep/24/theresa-may-calls-for-immigration-based-on-skills-and-wealth"
}

If you want to enable lighthouse analysis pass the following

var options = {
  url: "https://www.theguardian.com/politics/2018/sep/24/theresa-may-calls-for-immigration-based-on-skills-and-wealth",
  lighthouse: {
    enabled: true
  }
}

there are some additional "complex" options available

var options = {
  // array of html elements to stip before analysis
  striptags: [],
  // readability options (https://ghub.io/node-readability)
  readability: {},
  // retext spell options (https://ghub.io/retext-spell)
  retextspell: {}
}

Development

Please feel free to fork the repo or open pull requests to the development branch. I've used eslint for linting.

Build the dependencies with:

npm install

Lint the project files with:

npm run lint

Test the package with:

npm run test

Dependencies

  • Puppeteer: High-level API to control Chrome or Chromium over the DevTools Protocol
  • lighthouse: Automated auditing, performance metrics, and best practices for the web.
  • compromise: natural language processing in the browser
  • retext: Natural language processor powered by plugins
  • retext-pos: Plugin to add part-of-speech (POS) tags
  • retext-keywords: Keyword extraction with Retext
  • retext-spell: Spelling checker for retext
  • sentiment: AFINN-based sentiment analysis for Node.js
  • jquery: JavaScript library for DOM operations
  • jsdom: A JavaScript implementation of many web standards
  • lodash: Lodash modular utilities.
  • absolutify: Relative to Absolute URL Replacer
  • clean-html: HTML cleaner and beautifier
  • dictionary-en-gb: English (United Kingdom) spelling dictionary in UTF-8
  • html-to-text: Advanced html to plain text converter
  • nlcst-to-string: Stringify NLCST
  • node-readability: Turning any web page into a clean view.
  • vfile-reporter-json: JSON reporter for virtual files

Dev Dependencies

License

This project is licensed under the GNU GENERAL PUBLIC LICENSE Version 3 - see the LICENSE file for details

FAQs

Package last updated on 22 Aug 2019

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