【发布时间】:2014-03-11 09:41:49
【问题描述】:
我只想从我的 html 中提取文本
var sb = new StringBuilder();
doc.LoadHtml(inputHTml);
foreach (var node in Doc.DocumentNode.ChildNodes)
{
if (node.Name == "strong" || node.Name == "#text"
|| node.Name == "br" || node.Name == "div"
|| node.Name == "p" || node.Name != "img")
{
sb.Append(node.InnerHtml);
}
}
现在在我的 node.InnerHtml 中是这个 html:
1.
<br><div>text</div><div>, text</div><div>text<br>
<img src="http://example.com/55.jpg" alt="" title="" height="100">
<img src="http://example.com/45.jpg" alt="text" title="text" height="100"></div>
2.
text text text. <a
href="/content/essie-classics">text</a><br>
<img> src="" alt="" title="" height="100"><img
src="http://example.com/img_8862.jpg"
alt="" title="" height="100">
如何去除img和a标签?
img 标签没有结束标签
【问题讨论】:
标签: c# html html-agility-pack