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:
npm init -y
.npm install express cheerio body-parser axios
..js
extension (e.g., app.js
).app.js
file.node app.js
.GET /:
http://localhost:3000/
{
"message": "Hello, This is an unofficial API for India Today News",
"auth": "required"
}
GET /news/:tag?:
http://localhost:3000/news/sports
[
{
"tag": "Sports",
"title": "Sample Article Title",
"content": "Sample article content...",
"href": "https://www.indiatoday.in/sample-article"
},
...
]
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.