JSFiddle - React, Tailwind, and code Playground
by novikov433
JavaScript
// pl-scraper.js
const axios = require('axios');
const cheerio = require('cheerio');
const url = 'https://www.benzinga.com/stock/aapl/';
axios(url)
.then(response => {
const html = response.data;
const $ = cheerio.load(html)
const statsTable = $('#stories-headlines > ul > li');
const topPremierLeagueScorers = [];
statsTable.each(function () {
const author = $(this).find('.author').text();
const date = $(this).find('.date').text();
const url = $(this).find('a').text();
topPremierLeagueScorers.push({
author,
date,
url
});
});
console.log(topPremierLeagueScorers);
})
.catch(console.error);
const translate = require('@vitalets/google-translate-api');
translate(topPremierLeagueScorers.author, {to: 'ru'}).then(res => {
console.log(res.topPremierLeagueScorers.author);
//=> I speak English
console.log(res.from.language.iso);
//=> nl
}).catch(err => {
console.error(err);
});