本文介绍了HTMLAgilityPack中的innerHTML解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div>
<b>Token1</b>
Token2
<b>Token3</b>
</div>
我尝试从DIV
I try to extract Token2 from the div
我设法得到TOKEN1和Token3有:
I manage to get Token1 and Token3 with :
HtmlNodeCollection headerFooter = doc.DocumentNode.SelectNodes("//div//b");
我怎么能提取直接Token2与HTMLAgilityPack?
How can I extract directly Token2 with HTMLAgilityPack ?
一个肮脏的选择是在doc.DocumentNode.SelectNodes更换TOKEN1和Token2通过的String.Empty(//格)的InnerText,但我想它可以更清洁的方式已经完成与HTMLAgilityPack ...
One dirty option is to replace Token1 and Token2 by string.empty in doc.DocumentNode.SelectNodes("//div").InnerText, but I imagine it can been done in more clean way with HTMLAgilityPack...
推荐答案
的文本是在文本节点;所以你应该能够看到// DIV /文本()和连击:
The text is in the text nodes; so you should be able to look at "//div/text()" and concatenate:
StringBuilder sb = new StringBuilder();
foreach (HtmlAgilityPack.HtmlTextNode node in
doc.DocumentNode.SelectNodes("//div/text()"))
{
sb.Append(node.Text.Trim());
}
string s = sb.ToString();
这篇关于HTMLAgilityPack中的innerHTML解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!