Skip to content

Instantly share code, notes, and snippets.

<table>
<tr>
<th>Pet 1</th>
<th>Pet 2</th>
</tr>
<tr>
<td>Dog</td>
<td>Cat</td>
</tr>
</table>
const axios = require("axios");
const cheerio = require("cheerio");
const ObjectsToCsv = require("objects-to-csv");
(async function html_scraper() {
const response = await axios('https://datatables.net/examples/styling/display.html');
console.log(response.status)
})();
const html = await response.data;
const $ = cheerio.load(html);
const allRows = $('table.display &amp;gt; tbody &amp;gt; tr');
console.log(allRows.length)
allRows.each((index, element) =&amp;gt; {
const tds = $(element).find('td');
const name = $(tds[0]).text();
const position = $(tds[1]).text();
const office = $(tds[2]).text();
const age = $(tds[3]).text();
const startDate = $(tds[4]).text();
const salary = $(tds[5]).text();
employeeData = [];
employeeData.push({
'Name': name,
'Position': position,
'Office': office,
'Age': age,
'Start Date': startDate,
'Salary': salary,
})
const csv = new ObjectsToCsv(employeeData);
await csv.toDisk('./employeeData.csv')
const axios = require("axios");
const cheerio = require("cheerio");
const ObjectsToCsv = require("objects-to-csv");
employeeData = [];
(async function html_scraper() {
const response = await axios('https://datatables.net/examples/styling/display.html')
const html = await response.data;
const $ = cheerio.load(html);