Skip to content

Instantly share code, notes, and snippets.

@gagregrog
Last active October 28, 2020 22:39
Show Gist options
  • Save gagregrog/5edf44927cb0f441f9306ba6b9ba63a7 to your computer and use it in GitHub Desktop.
Save gagregrog/5edf44927cb0f441f9306ba6b9ba63a7 to your computer and use it in GitHub Desktop.
Grab key value pairs of data cells for rows 1,3,4,5
const cheerio = require('cheerio');
const re = new RegExp('[1345]');
const parseHtml = (html) => {
const $ = cheerio.load(html);
const trs = $('#result-card > div > table > tbody > tr');
const results = [];
trs.each((trIdx, tr) => {
if (re.test(trIdx)) {
const tds = $('td', tr);
if (tds.length === 2) {
const kvPair = [];
tds.each((tdIdx, td) => {
kvPair.push(getText(td));
});
results.push(kvPair);
} else console.log('Found too many tds', tds);
}
});
return results;
}
function getText(node) { ... }
module.exports = parseHtml;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment