c# - 如何从 html 源中提取页面上可见的文本?

标签 c# html

我试过 HtmlAgilityPack 和下面的代码,但它没有从 html 列表中捕获文本:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(htmlStr);
HtmlNode node = doc.DocumentNode;
return node.InnerText;

这是失败的代码:

<as html>
<p>This line is picked up <b>correctly</b>.  List items hasn't...</p>
<p><ul>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li> 
<li>List Item 4</li>
</ul></p>
</as html>

最佳答案

因为您需要遍历树并以某种方式连接所有节点的 InnerText

关于c# - 如何从 html 源中提取页面上可见的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9153877/

相关文章:

c# - 如何播放要在设定的延迟下重复播放的音频片段阵列?

javascript - 异步请求 Web 资源的特定部分

javascript - 绘制到 html Canvas 中的 png 图像质量差

PHP isset ('submit' ) 总是返回 FALSE

html - 导航切换不适用于 768px 宽度的 Bootstrap

c# - 这是如何抛出 InvalidCastException

c# - 在 div id 上使用 FindControl 时出错

c# - 如何将用户定义类型的数组传递给存储过程

html - 页脚仅在 safari 中看起来不正确

c# - 正则表达式模式中的相同变量