I am struggling to apply selectors to elements in cheerio (version 1.0.0-rc.3). Attempting to use find()
results in an error.
const xmlText = `
<table>
<tr><td>Foo</td><td/></tr>
<tr><td>1,2,3</td><td>number</td></tr>
<tr><td>A,B</td><td>char</td></tr>
<!-- more rows -->
</table>
<table>
<tr><td>Bar</td><td/></tr>
<!-- more rows -->
</table>
`
const $ = cheerio.load(xmlText)
$('table').each((i, table) => {
// TODO if first row contains Foo then map the following rows
if (table.find("td:contains('Foo')").length > 0) {
// ...
}
})
'CheerioElement' does not have a property 'find'.
How can I access sub elements using selectors?
I want the example given to only process tables with the text 'Foo' in the first row and return a list of objects as shown below.
// desired result
[{ value: '1,2,3', type: 'numbner' }, { value: 'A,B', type: 'char' }, ...]