India Today Unofficial

FREEMIUM
By PRANSHU JAIN | Updated 1ヶ月前 | News, Media
Popularity

7.8 / 10

Latency

77,077ms

Service Level

100%

Health Check

N/A

README

The provided code is an example of a Node.js application that serves as an unofficial API for fetching news articles from the India Today website. Below is the documentation for this API:

Installation and Setup

  1. Make sure you have Node.js installed on your system.
  2. Create a new directory for your project and navigate to it using the command line.
  3. Initialize a new Node.js project by running the command: npm init -y.
  4. Install the required dependencies by executing the command: npm install express cheerio body-parser axios.

Usage

  1. Open a text editor and create a new file. Copy the provided code into the file and save it with a .js extension (e.g., app.js).
  2. In the terminal, navigate to the project directory containing the app.js file.
  3. Start the server by running the command: node app.js.
  4. The server should now be running and listening on the specified port (default is 3000).
  5. You can access the API endpoints using a tool like cURL or a web browser.

Endpoints

  • GET /:

    • Returns a welcome message and authentication requirement.
    • Example: http://localhost:3000/
    • Response:
      {
        "message": "Hello, This is an unofficial API for India Today News",
        "auth": "required"
      }
      
  • GET /news/:tag?:

    • Returns news articles, optionally filtered by a specific tag.
    • Example: http://localhost:3000/news/sports
    • Response:
      [
        {
          "tag": "Sports",
          "title": "Sample Article Title",
          "content": "Sample article content...",
          "href": "https://www.indiatoday.in/sample-article"
        },
        ...
      ]
      
    • If no tag is provided, it returns all news articles.

Functionality

The API provides two main functionalities through the /news endpoint:

  • Extracting the href attribute of all ‘a’ tags that are children of a specific ‘div’ tag. This is done by calling the extractHref function.

  • Extracting the text content of all elements that match a specific selector. This is done by calling the extractText function.

The API utilizes the Cheerio library to parse and traverse the HTML structure of the India Today website. It uses Axios to make HTTP requests to fetch the HTML content of the website.

The extracted data, including the news articles’ tags, titles, content, and URLs, is returned as a JSON response.

Please note that this code is an unofficial implementation and may not be as reliable or comprehensive as an official API provided by India Today. The availability and functionality of this API may be subject to change based on updates to the India Today website structure.

Followers: 0
Resources:
Product Website
API Creator:
Rapid account: PRANSHU JAIN
PRANSHU JAIN
pranshujain0111
Log In to Rate API
Rating: 5 - Votes: 1