npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

newspaperjs

v1.0.8

Published

News extraction and scraping. Article Parsing

Downloads

318

Readme

Newspaperjs

News extraction and scraping. Maximizing the power of Request and Cheerio.

Inspired by "Codelucas - Python Newspaper lib"

Features

  • News url identification
  • News Categories extraction
  • Text extraction from html
  • Top image extraction from html
  • Description extraction from html
  • Keyword extraction from html
  • Author extraction from html

Installation

npm install newspaperjs

Using API

const Build = require('newspaperjs').Build;
const Article = require('newspaperjs').Article

Building a news source

Building a Source will extract its categories and articles url with two simple methods.

.getCategoriesUrl(url{string}, cateOfInterest[array])

Get all categories url. When cateOfInterest is specified, it's only extract their links if found. Returns Promise, an array of categories url.

Build.getCategoriesUrl('https://www.nytimes.com', ['politics', 'sports', 'technology']).then(categories=>{
    console.log(categories); 
}).catch(reason=>{
    console.log(reason);
})
//[
     'https://www.nytimes.com/pages/politics'
     'https://www.nytimes.com/pages/sports',
     'https://www.nytimes.com/pages/technology'
  ]

.getArticlesUrl(categoriesUrl{string})

Get all articles url from a category url. Returns Promise, array of articles url.

 Build.getArticlesUrl('https://www.nytimes.com/pages/politics').then(result=>{
    console.log(result);
}).catch(reason=>{
    console.log(reason)
})
//[
   'https://www.nytimes.com/2017/06/12/us/politics/trump-travel-ban-court-of-appeals.html',
  'https://www.nytimes.com/aponline/2017/06/12/us/politics/ap-us-trump-lawsuit-the-latest.html',
  'https://www.nytimes.com/aponline/2017/06/12/us/politics/ap-us-supreme-court-biotech-drugs.html',
  'https://www.nytimes.com/2017/06/12/us/trump-lawsuit-private-businesses.html',
  'https://www.nytimes.com/2017/06/12/us/politics/ivanka-trump-comey-donald-trump-fox-and-friends.html',
  'https://www.nytimes.com/2017/06/12/us/politics/unions-come-into-the-justices-cross-hairs-again.html',
  'https://www.nytimes.com/2017/06/11/us/politics/ducks-washington-reflecting-pool-unity.html',
  'https://www.nytimes.com/2017/06/11/us/politics/preet-bharara-trump-contacts.html',
  'https://www.nytimes.com/2017/06/11/us/politics/jeff-sessions-russia-trump-attorney-general-senate.html',
  'https://www.nytimes.com/2017/06/11/us/politics/defense-secretary-jim-mattis-trump.html',
...]

Extracting and Parsing News Article.

Extract news article using the article url provided and parse the content.

.Article(url{string})

Extract and Parse news article, in order to access title, text, topImage, date, author, description and keywords of the article.

Article('https://www.nytimes.com/2017/06/10/us/politics/sessions-senate-russia-election.html')
.then(result=>{
    console.log(result);
}).catch(reason=>{
    console.log(reason);
})
{
    title: 'Sessions Will Testify in Senate on Russian Meddling in Election',

    text: " AdvertisementBy CHARLIE SAVAGEJUNE 10, 2017\nWASHINGTON — Attorney General Jeff Sessions told Congress on Saturday that he would testify before the Senate Intelligence Committee on Tuesday about issues related to Russia’s interference in the 2016 election.  Mr. Sessions had been scheduled to testify before other committees about the Justice Department’s budget that day, but he will instead appear before the intelligence panel. Mr.Sessions said he would send Rod J. Rosenstein, the deputy attorney general, to testify about the department’s budget before the House and Senate appropriations panels.... ",

    topImage:'https://static01.nyt.com/images/2017/06/11/us/11dcSESSIONS/11dcSESSIONS-facebookJumbo.jpg',

    date: '2017-06-10T20:08:09-04:00',

    author: 'Charlie Savage',

    description: 'Instead of discussing the Justice Department budget, Attorney General Jeff Sessions will face questions from members of Congress who have access to intelligence materials on the Russia inquiry.',

    keywords: [ 'Russian Interference in 2016 US Elections and Ties to Trump Associates', 'Sessions  Jefferson B III', 
    'Justice Department', 
    'United States Politics and Government', 'Attorneys General', 
    'Senate Committee on Intelligence','Trump  Donald J', 'Comey  James B' ]
}

Author

Authored and maintained by Oluwaseun Omoyajowo. Like to get in touch?

Email: [email protected]

Twitter: @oluwaseunOmoya