Last active
October 28, 2020 22:39
-
-
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
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 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