1const Apify = require('apify');
2const request = require('request-promise');
3const extractor = require('unfluff');
4
5Apify.main(async () => {
6 const { url } = await Apify.getValue('INPUT');
7
8 if (!url) throw new Error('INPUT.url must be provided!!!');
9
10 console.log('Opening browser ...');
11 const browser = await Apify.launchPuppeteer();
12
13 console.log('Loading url ...');
14 const page = await browser.newPage();
15 await page.goto(url, { waitUntil: 'domcontentloaded' });
16 const html = await page.evaluate(() => document.documentElement.outerHTML);
17
18 await Apify.setValue('page.html', html, { contentType: 'text/html' });
19
20 console.log('Extracting article data and saving results to key-value store ...');
21 await Apify.setValue('OUTPUT', extractor(html));
22
23 console.log('Done!');
24});