简体   繁体   中英

Any way to get nearby html nodes different from current node's tag name in NodeJS?

Let's say I have the following html code..

<html>
<head></head>
<body>  
  <div>
    <input type ="text">
    <img src = "pic.jpg">
    <a href ="index.html">Home</a>
  </div>
</body>
</html>

And I want to look at the nodes around an element that's on the same level. For example, from the above html code, is it possible to do something like...

 $("input").returnNodesOnSameLevel()

and it can return a list of nodes which here would contain [< input...>, < a...> ] ?

I'm using NodeJS's request module to grab the page source and then using Cheerio to do my parsing. The sibling() only returns nodes of the same tag name which makes sense. If there's a better module or another way to do this, please let me know.

Thank you.

如果$("input").siblings()不起作用,则可以尝试: $("input").parent().children()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM