1
2
3
4
5
6
7const Apify = require('apify');
8const { handleStart, handleList, handleDetail } = require('./src/routes');
9
10const { utils: { log } } = Apify;
11
12Apify.main(async () => {
13 const { startUrls } = await Apify.getInput();
14
15 const requestList = await Apify.openRequestList('start-urls', startUrls);
16 const requestQueue = await Apify.openRequestQueue();
17 const proxyConfiguration = await Apify.createProxyConfiguration();
18
19 const crawler = new Apify.PuppeteerCrawler({
20 requestList,
21 requestQueue,
22 proxyConfiguration,
23 launchContext: {
24
25
26 useChrome: true,
27 stealth: true,
28 },
29 handlePageFunction: async (context) => {
30 const { url, userData: { label } } = context.request;
31 log.info('Page opened.', { label, url });
32 switch (label) {
33 case 'LIST':
34 return handleList(context);
35 case 'DETAIL':
36 return handleDetail(context);
37 default:
38 return handleStart(context);
39 }
40 },
41 });
42
43 log.info('Starting the crawl.');
44 await crawler.run();
45 log.info('Crawl finished.');
46});