Skip to content

Instantly share code, notes, and snippets.

@Hyllesen
Last active January 27, 2020 14:25
Show Gist options
  • Save Hyllesen/f8fbfc9539c7d4fa2af4d1c2af25ee60 to your computer and use it in GitHub Desktop.
Save Hyllesen/f8fbfc9539c7d4fa2af4d1c2af25ee60 to your computer and use it in GitHub Desktop.
const request = require("request-promise");
const cheerio = require("cheerio");
async function main() {
const result = await request.get("http://codingwithstefan.com/table-example");
const $ = cheerio.load(result);
const scrapedData = [];
$("body > table > tbody > tr").each((index, element) => {
if (index === 0) return true;
const tds = $(element).find("td");
const company = $(tds[0]).text();
const contact = $(tds[1]).text();
const country = $(tds[2]).text();
const tableRow = { company, contact, country };
scrapedData.push(tableRow);
});
console.log(scrapedData);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment