({ request, addRequests, pushData })
| 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']); |
nothing calls this directly
no test coverage detected
searching dependent graphs…