Unable to scrape the link in <a class="btn _def _i _sm" href="www.page2.com"> using cheerio

Viewed 22

Unable to scrape the link from the element below using cheerio

 const outputFile= 'data.json'
 const parsedResults =[]
 const pagelimit = 50
 let pageCounter = 0
 let resultCount = 0

const getWebsiteContent = async(url)=>{
  try{
 const response = await axios.get(url)
 const nextPageLink =  $('a.btn._def._i._sm', response.data).attr('href');
 console.log(nextPageLink);
      } 
 catch(error){
 console.error(error)
   }
 }
getWebsiteContent(url);`

I tried to select the class in the code above by using $('a.btn._def._i._sm', hmtl) but its not working.I keep getting null.

enter image description here

Please has anyone encountered this issue before and how did they solve it?

0 Answers
Related