Currently, I am trying to build a scrapper that searches all <a> tags for specific keywords like "climate" or "environment." Using cheerio, is it possible to look for multiple keywords so that I get results of multiple keywords?
Here is my code-
const PORT = 8000;
const express = require('express');
const axios = require('axios');
const cheerio = require('cheerio');
const { response } = require('express');
const app = express();
const articles = [];
app.get('/',(req,res)=>{
res.json('Hello World')
})
app.get('/news',(req,res)=>{
axios.get('https://www.tbsnews.net/bangladesh/environment/climate-change')
.then((response)=>{
const html = response.data;
const $ = cheerio.load(html);
$('a:contains("climate")',html).each(function(){
const title = $(this).text()
const url = $(this).attr('href')
articles.push({
title,
url
})
})
res.json(articles)
}).catch((err)=>console.log(err));
})
app.listen(PORT,()=>{console.log(`server running on Port ${PORT}`)});