1const Apify = require('apify');
2
3const { log } = Apify.utils;
4
5Apify.main(async () => {
6 let {
7 datasetId,
8 resource,
9 taskIdOrName
10 } = await Apify.getInput();
11 if (!datasetId && resource) {
12 datasetId = resource.defaultDatasetId;
13 }
14
15 log.info(`Loading dataset: ${datasetId}`)
16
17 const dataset = await Apify.openDataset(datasetId);
18 const { items } = await dataset.getData({
19 clean: true,
20 fields: ['url']
21 });
22
23 log.info(`Loaded ${items.length} URLs from the dataset`);
24
25 const directUrls = items.map((item) => item.url);
26
27 log.info(`Calling actor to scrape posts`);
28
29 let run;
30
31 if (taskIdOrName) {
32 run = await Apify.callTask(
33 taskIdOrName,
34 { directUrls, resultsType: 'comments'},
35 { waitSecs: 0 }
36 )
37 } else {
38 const actorInput = {
39 directUrls,
40 resultsType: 'comments',
41 "proxy": {
42 "useApifyProxy": true,
43 "apifyProxyGroups": [
44 "RESIDENTIAL"
45 ]
46 },
47 "resultsLimit": 1000,
48 }
49 run = await Apify.call(
50 'jaroslavhejlek/instagram-scraper',
51 actorInput,
52 { waitSecs: 0 }
53 )
54 }
55
56 log.info(`Started run to scrape posts with ID: ${run.id}`);
57 log.info(`You can view the run here:`);
58 log.info(`https://my.apify.com/actors/shu8hvrXbJbY3Eb9W#/runs/${run.id}`)
59
60});