Puppeteer get page.content with recursive iteration to get all result of paginate list -


i want results of paginate list of data puppeteer.

if make cycle give error:

(node:54961) unhandledpromiserejectionwarning: unhandled promise rejection (rejection id: 1): error: protocol error (runtime.evaluate): cannot find context specified id undefined  (node:54961) deprecationwarning: unhandled promise rejections deprecated. in future, promise rejections not handled terminate node.js process non-zero exit code. 

this code:

const puppeteer = require('puppeteer'); var sleep = require('sleep');  function getrandomint(min, max) {     return math.floor(math.random() * (max - min + 1)) + min; }  (async () => { const browser = await puppeteer.launch({headless: false}); const page = await browser.newpage();  console.log('start'); page.on('console', (...args) => console.log('page log:', ...args));  await page.goto('pageurl'); var num = 0; for(var i=0; i< 10; i++){     var content = await page.content();     console.log('we have content of page '+num);     var fs = require('fs');     fs.writefilesync("htmls/"+num+".html", content);     console.log("the file of page "+num+" saved!");      var sleepsecond = getrandomint(20,40);     console.log("we waiting "+ sleepsecond + " seconds");     sleep.sleep(sleepsecond);      var inputelement = await page.$('a.next');     await inputelement.click();     console.log('click on next');     sleepsecond = getrandomint(40,80);     console.log("we waiting "+ sleepsecond + " seconds");     sleep.sleep(sleepsecond);     num +=15; }  browser.close(); })(); 

so how solve error , how transform cycle in recursive cycle?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -