Skip to content

Instantly share code, notes, and snippets.

@ravindu01manoj
Created February 5, 2023 13:59
Show Gist options
  • Save ravindu01manoj/485d2547e6b15c458da9b3545a2dffdf to your computer and use it in GitHub Desktop.
Save ravindu01manoj/485d2547e6b15c458da9b3545a2dffdf to your computer and use it in GitHub Desktop.
//Copyrigth - Ravindu Manoj (https://github.com/ravindu01manoj/)
var axios = require('axios')
var cheerio = require('cheerio')
async function news() {
var old = [];
var Func = async ()=>{
var data = await axios.get('https://nethnews.lk')
var l = cheerio.load(data.data)
var news_url = l('div.top_breaking_news_content > div.td-read-more > a').attr('href')
if(old.includes(news_url.split('article/')[1])) return;
old.push(news_url.split('article/')[1])
var result = {
news_url,
title: l('div.top_breaking_news_title > h3').text().trim(),
date: l('div.top_breaking_news_title > div. publish_date').text().trim(),
short_desc : l('div.top_breaking_news_content > div.top_breaking_news_discription').text().trim(),
desc: cheerio.load((await axios.get(news_url)).data)('div.content_left > div > div > div > div.td-post-content').text().trim(),
views : l('div.top_breaking_news_content > div.td-post-views').text().trim(),
img: l('div.top_breaking_news_image > img').attr('src')
}
// console.log(result)
// do something With Results
}
setIntraval(Func,10 * 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment