这是一个HTML片段,我想要的只是获取文本节点并迭代它们.请告诉我.谢谢.
<div>
<div>
Select your Age:
<select>
<option>0 to 10</option>
<option>20 and above</option>
</select>
</div>
<div>
Help/Hints:
<ul>
<li>This is required field.
<li>Make sure select the right age.
</ul>
<a href="#">Learn More</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
结果:
Sim*_*ier 20
像这样的东西:
HtmlDocument doc = new HtmlDocument();
doc.Load(yourHtmlFile);
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//text()[normalize-space(.) != '']"))
{
Console.WriteLine(node.InnerText.Trim());
}
Run Code Online (Sandbox Code Playgroud)
输出这个:
Select your Age:
0 to 10
20 and above
Help/Hints:
This is required field.
Make sure select the right age.
Learn More
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9877 次 |
| 最近记录: |