get text of all

in div htmlagilitypack

.net html-agility-pack parsing winforms

Question

i have a div that which contains paragraph tags like this

<div class="div_5">
                <p>First Paragraph</p>
                <p>Second Paragraph</p>
                <p>Third Paragraph</p>
                <p>Fourth Paragraph</p>
 </div>
<div class="div_5">
                <p>First Paragraph</p>
                <p>Second Paragraph</p>
                <p>Third Paragraph</p>
                <p>Fourth Paragraph</p>
 </div>

i need to get the text of all paragrap text using htmlagiitypack i tried this,

Dim oPB As HAP.HtmlNodeCollection = doc.DocumentNode.SelectNodes("//div[@class='post-bodycopy clearfix']/child::text()/"]
For Each item As HAP.HtmlNode In oPB
                    debug.print(item.InnerText)
                Next

the output am expecting for each div string is

First Paragraph
Second Paragraph
Third Paragraph
Fourth Paragraph

but am getting some html in the text returned, can someone help me correct the problem

1
1
6/15/2012 6:02:42 AM

Accepted Answer

You have to actually select the paragraphs' inner text. Your xpath gets something else completely.

Dim query = doc.DocumentNode.SelectNodes("//div[@class='div_5']/p/text()")
2
6/15/2012 6:09:32 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow