Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query node-html-parser path with classes

I am stuck with node-html-parser (https://www.npmjs.com/package/node-html-parser). I read HTML into local variable and I am trying to get to the following node (JS path that is copied from Chrome):

#container > section > div > div.profile__main > div.item.item__profile > div.item__profile__info.cf > div.item__profile__info__data > p

Unfortuantely I get stuck at div.profile__main . (profile__main is a class within div and the tag looks like <div class="profile__main" ...></div>

How do I query for this stuff. So far I got only here:

var root = this.HTMLParser.parse(this.data)
root.querySelectorAll("#container")
      .querySelectorAll("section")
      .querySelectorAll("div")
      .querySelector("div.profile__main") // Cant get this one. returns null

Thanks

like image 784
Witold Kaczurba Avatar asked Mar 24 '26 21:03

Witold Kaczurba


1 Answers

const root = this.HTMLParser.parse(this.data)
const itemProfileInfoData = root.getElementsByTagName("div").find(div => div.attributes.class === "item__profile__info__data")
itemProfileInfoData.childNodes.filter(child => child.tagName === "p")
like image 91
Juani D'Ambrosio Avatar answered Mar 27 '26 15:03

Juani D'Ambrosio