1const Apify = require('apify');
2const _ = require('underscore');
3
4Apify.main(async () => {
5
6 const input = await Apify.getValue('INPUT');
7 console.log('Input:')
8 console.dir(input);
9 if (!input || !input._id) {
10 throw new Error('Input is missing the "_id" attribute. Did you start it from crawler finish webhook?');
11 }
12 const executionId = input._id;
13
14
15 const crawlerRunDetails = await Apify.client.crawlers.getExecutionDetails({ executionId });
16 if (!crawlerRunDetails) {
17 throw new Error(`There is no crawler run with ID: "${executionId}"`);
18 }
19 console.log(`Details of the crawler run (ID: ${executionId}):`);
20 console.dir(crawlerRunDetails);
21
22
23
24 console.log(`Counting results from crawler run...`);
25
26 const limit = 100;
27 let offset = 0;
28 let totalItems = 0;
29 let results;
30
31 do {
32 results = await Apify.client.crawlers.getExecutionResults({
33 executionId,
34 limit,
35 offset
36 });
37
38 offset += results.count;
39 totalItems += results.items.length;
40 } while (results.count > 0);
41
42
43 console.log(`Found ${totalItems} records`);
44 await Apify.setValue('OUTPUT', {
45 crawlerRunDetails,
46 totalItems
47 });
48
49});