Public
Edited
Dec 9, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
params = {
let params = new URLSearchParams();
return params;
}
Insert cell
Insert cell
Insert cell
Insert cell
$ = cheerio.load(result)
Insert cell
options = ({
headerclass: "thead",
bodyclass: "tbody"
})
Insert cell
scrapedData = {
const scrapedData = [];

// colnames
const headers = $("table " + options.headerclass);
const cols = $(headers.eq(0)).find("span[class]");
// console.log(cols);
let colnames = [];
cols.each((index, element) => {
colnames.push($(element).text());
});
console.log(colnames);

const tables = $("table " + options.bodyclass);
$(tables.eq(0))
.find(options.bodyclass + " tr")
.each((index, element) => {
// create lines
const tds = $(element).find("td");
let row = {};
// iterate
for (let i = 0; i < colnames.length; i++) {
row = Object.assign(row, { [colnames[i]]: $(tds[i]).text() });
}
// push
scrapedData.push(row);
});
return scrapedData;
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more