html - Get Text from<p> using HttpAgilityPack -
i using code return text html "p" tag
htmldocument doc = new htmldocument(); doc.loadhtml(content); string query = doc.documentnode.selectsinglenode("//p/text()").innertext; if (query.length >0) { query = query.substring(0, 60) + "..."; } > here problem if "p" tag contains tag not return text. ex.
<p><img src="http://localhost:49171/images/myimages/80ef7d03-6a8b-49e2-a4da-fa9f5f1773dd.jpg" alt="" />thank choosing microsoft windows 8.1 pro. license agreement between , microsoft corporation (or, based on live, 1 of affiliates) </p> in code, query returns "images/myimages/80ef7d03-6a8b-49e2-a4da-fa9f5f1773dd.jpg",
anybody please me retrive these lines "thank choosing microsoft windows 8.1 pro." instead of "images/myimages/80ef7d03-6a8b-49e2-a4da-fa9f5f1773dd.jpg".
thanks in advance...
since every text node in htmlagilitypack has name #text can following:
string query = doc.documentnode.descendants("p") .first() .childnodes.first(node => node.name == "#text").innertext; this takes first <p> node in document , selects inner text of first text node direct child of <p> node.
Comments
Post a Comment