Parse a div with HTML Agility Pack

c# html html-agility-pack html-parsing parsing

Question

I've this HTML code:

div class="singolo-contenuto link_azure">
<p><img src="" class="left pad2 field_foto" alt="" /><p> Message </p>    
</div>

I need to "capture" "Message". I'm trying with:

String message = htmlDoc.DocumentNode.SelectSingleNode("//div[@class='singolo-contenuto link_azure']").InnerText;

but doesn't works... I obtain a lot of the full page... what's wrong?

1
0
7/13/2014 11:20:04 PM

Popular Answer

The XPath expression you have just gets you to the <div> tag. You need to get deeper into the last <p> tag. This will work:

var message = htmlDoc.DocumentNode.SelectSingleNode("//div[@class='singolo-contenuto link_azure']//p[last()]").InnerText;
0
7/14/2014 3:37:25 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