Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

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

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?

question from:https://stackoverflow.com/questions/65904833/unable-to-scrape-the-link-in-a-class-btn-def-i-sm-href-www-page2-com-us

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...