简体   繁体   中英

how to convert this Puppeteer script to Puppeteer cluster

how can I convert this script from puppeteer to puppeteer cluster

const URL = process.argv[2];
puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] }).then(async browser => {
    const page = await browser.newPage();
    await page.setViewport({width: 1, height: 1});
    await page.setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 9_0_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13A404 Safari/601.1');
    await page.goto(URL);
    console.error('found');
    await page.waitForSelector('body.blog');
    await browser.close();
    process.exit();
}).catch(function(error) {
    console.error('sucess');
    process.exit();
});

When you make the cluster, you queue up tasks which are essentially functions that the cluster will try to execute in the order you specify.

I have an open question here which you can use to learn the structure of the cluster queue. But definitely recommend you also re-read TD's documentation on the Github

And if anyone is feeling generous and could help me with my question...I'm still trying to run tests to figure it out...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM