Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js can';“找不到下一步”按钮以导航到其他页面_Node.js - Fatal编程技术网

Node.js can';“找不到下一步”按钮以导航到其他页面

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 => {

我正在使用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 => {
            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页然后完成运行 有人知道为什么吗