html agility pack - How to get elements inside of commented out code HtmlAgilityPack in VB.NET -
html agility pack - How to get elements inside of commented out code HtmlAgilityPack in VB.NET -
is there way utilize htmlagilitypack on html within <!-- -->
comment blocks? example, how can target inner text of "//div.[@class='theclass']"
within block this:
<!-- <div class="theclass'>hello <span class="thespan">some text.</span> </div>-->
so
hello text.
the reason inquire because kept finding kept returning null, because div
's within comments:
htmlnodes = htmldoc.documentnode.selectnodes("//div[@class='theclass']")
unfortunately, xpath treats comment node content plain text, means can't query content mutual nodes.
one possible way parse comment node content htmldocument
can query it, illustration :
'get desired comment node' dim htmlnode htmlnode = htmldoc.documentnode.selectsinglenode("//comment()[contains(., theclass)]") dim comment new htmldocument() 'remove outer <!-- --> have clean content' comment.loadhtml(htmlnode.innerhtml.replace("<!--", "").replace("-->", "")) 'here can utilize mutual xpath query again' dim result htmlnode = comment.documentnode.selectsinglenode("//div[@class='theclass']") 'following line print "hello text."' console.writeline(result.innertext)
vb.net html-agility-pack
Comments
Post a Comment