Git Product home page Git Product logo

inshorts-news-scraper's Introduction

Inshorts News Scraper

I've written a Node.js module that scrapes news articles from the popular news aggregator Inshorts. The module utilizes the cheerio and node-fetch libraries to parse HTML and make HTTP requests, respectively.

I'm Harshit Sharma, also known as harshitehic online.

Installation

To use this module in your Node.js project, you can install it via npm:

npm install inshorts-news-scraper

Usage

To use this module, you can import it into your Node.js file:

const inshortsScraper = require('inshorts-news-scraper');

getNews function

The getNews function takes in two arguments: options and callback. options is an object that contains the language and category of the news to be scraped. callback is a function that will be called with the scraped news data and the news_offset parameter (used for pagination).

const options = {
  lang: 'en',
  category: 'national',
};

inshortsScraper.getNews(options, (news, news_offset) => { console.log(news); console.log(news_offset); });

getMoreNews function

The getMoreNews function is similar to getNews, but it is used for pagination. It takes in an additional parameter, options.news_offset, which is used to request the next page of news articles. The function sends an HTTP POST request to the Inshorts website with the given options, then scrapes the HTML using cheerio to extract the relevant news data. The scraped data is stored in an array of objects, where each object represents a single news article. The function then calls the callback function with the scraped data and the new news_offset parameter.

const options = {
  lang: 'en',
  category: 'national',
  news_offset: 'jvn36k2y-1',
};

inshortsScraper.getMoreNews(options, (news, news_offset) => { console.log(news); console.log(news_offset); });

Author

This module was written by Harshit Sharma, also known as harshitehic online. You can learn more about him and his work on his website, harshitethic.in.

License

This module is licensed under the MIT License.

inshorts-news-scraper's People

Contributors

harshitethic avatar

Stargazers

Shafqat Abbas avatar Harshit Sharma avatar

Watchers

 avatar

Forkers

harshitethic001

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.