The following question is similar but the answer are useless: How to get children of elements by Puppeteer. In these answers, users show how to get an attribute of an element. I need to access list of child nodes.
In the page I'm scraping there are 30 boxes with really complex and different content.
My goal was to
- obtain the external boxes (DIV
s)
- check if some spceific nested html elements are present
- retrieve content of nested element
For example
- first box has image with nested link
- second box has 4 <P>
s
I am able, thanks to an answer to my previous question to retrieve all DIV
s
I am doing this
const boxes = await page.$$("DIV.a-row DIV.spinnerDeal DIV.box DIV.details")
boxes.forEach((item) => {
... now, for example how to check if the item contains a P with a specific class=
})
So my question is (for example) how to check if the item contains a P with a specific class.
More general question is how to browser nested elements of each item ?
I tried
boxes.forEach((item) => {
console.log(item.getChildNodes())
console.log("---")
})
But getChildNodes() is not a function