Last active
January 27, 2020 14:25
-
-
Save Hyllesen/f8fbfc9539c7d4fa2af4d1c2af25ee60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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