1
2const Apify = require('apify');
3const cheerio = require('cheerio');
4
5Apify.main(async () => {
6
7
8
9
10 const input = await Apify.getInput();
11 console.log('Actor input:');
12 console.dir(input);
13
14
15 const currencyFrom = input.from || 'MXN';
16 const currencyTo = input.to || 'USD';
17 const amount = input.amount || 1;
18 const url ='https://www.google.com/search?q='+amount+'+'+currencyFrom+'+to+'+currencyTo;
19 const { body } = await Apify.utils.requestAsBrowser({ url });
20
21
22 const $ = cheerio.load(body);
23 const rate = $('#knowledge-currency__updatable-data-column div[data-exchange-rate]').attr('data-exchange-rate');
24
25
26 const output = {
27 info: ''+amount+' '+currencyFrom+' = '+(parseFloat(amount)*rate)+' '+currencyTo,
28 from: currencyFrom,
29 to: currencyTo,
30 amountSource: amount,
31 amountConverted: parseFloat(amount)*rate,
32 rate: rate,
33 crawledAt: new Date()
34 };
35 console.log('Actor output:');
36 console.dir(output);
37 await Apify.setValue('OUTPUT', output);
38});