MCPcopy
hub / github.com/apify/crawlee / requestHandler

Function requestHandler

test/e2e/request-queue-with-concurrency/actor/main.js:28–48  ·  view source on GitHub ↗
({ request, addRequests, pushData })

Source from the content-addressed store, hash-verified

26 const crawler = new BasicCrawler({
27 requestQueue,
28 async requestHandler({ request, addRequests, pushData }) {
29 await setTimeout(Math.random() * 200); // Simulate some work
30
31 const url = new URL(request.url);
32 const index = Number(url.pathname.slice(1));
33 const newUrls = [];
34
35 for (const newIndex of [index + 1, index + 2, 2 * index]) {
36 if (newIndex <= input.limit) {
37 url.pathname = `/${newIndex + 1}`;
38 newUrls.push(url.toString());
39 }
40 }
41
42 log.info(`Enqueueing ${newUrls.length} new urls`);
43 if (newUrls.length > 0) {
44 await addRequests(newUrls);
45 }
46
47 await pushData({ url });
48 },
49 });
50
51 await crawler.run(['https://example.tld/1']);

Callers

nothing calls this directly

Calls 3

addRequestsFunction · 0.85
pushMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…