Node.js can';“找不到下一步”按钮以导航到其他页面
我正在使用Puppeter从cluth.co这样的网站上获取一些URL 下面是函数get some URL和next按钮的代码:Node.js can';“找不到下一步”按钮以导航到其他页面,node.js,Node.js,我正在使用Puppeter从cluth.co这样的网站上获取一些URL 下面是函数get some URL和next按钮的代码: async function scrapeCurrentPage(){ await page.waitForSelector(container) //get all the link on page let urls = await page.$$eval(detail, links => {
async function scrapeCurrentPage(){
await page.waitForSelector(container)
//get all the link on page
let urls = await page.$$eval(detail, links => {
links = links.map(el => el.href)
return links
})
for(link in urls){
let currentPageData = urls[link]
scrapedData.push(currentPageData)
}
//next button
let nextButtonExist = false
try{
const nextButton = await page.$eval(next_btn, a => a.textContent)
nextButtonExist = true
}
catch(err){
nextButtonExist = false
}
if(nextButtonExist){
count++
await page.click(next_btn)
console.log(`Navigating to page ${count+1}`)
return scrapeCurrentPage()
}
await page.close()
return scrapedData
}
但当运行时,有时它可以继续转到第10页或更多页,有时它只能转到第2页然后完成运行
有人知道为什么吗