Puppeteer Scraper avatar

Puppeteer Scraper

Try for free

No credit card required

Go to Store
Puppeteer Scraper

Puppeteer Scraper

apify/puppeteer-scraper
Try for free

No credit card required

Crawls websites with the headless Chrome and Puppeteer library using a provided server-side Node.js code. This crawler is an alternative to apify/web-scraper that gives you finer control over the process. Supports both recursive crawling and list of URLs. Supports login to website.

MP

Delay or setTimeout() FUNCTION

Closed
modest_programmer opened this issue
7 months ago

the scraper is not responding to a setTimeout function.

I want the Apify puppeteer scraper to return some data and then after that it should delay 20 seconds before it clicks a button on the page. How can this be achieved.

jindrich.bar avatar

Hello and thank you for your interest in this Actor!

Apologies for the delay in responding to your issue.

You can easily achieve this delay using the Promise constructor with setTimeout trick, as shown below:

1log.info(+Date.now());
2
3await new Promise(r => setTimeout(r, 5000));
4
5log.info(+Date.now());

This code runs in the Page function and will log two timestamps that are 5000 milliseconds apart. You can adapt this approach to introduce a 20-second delay before clicking a button. Make sure to update the Actor timeouts appropriately.

I'll go ahead and close this issue, but feel free to open a new one if you need further assistance!

Developer
Maintained by Apify

Actor Metrics

  • 446 monthly users

  • 96 bookmarks

  • >99% runs succeeded

  • 33 days response time

  • Created in Apr 2019

  • Modified 8 months ago