如何使用 Linq 和 HtmlAgilitypack 从正文标签中获取 p 标签中的文本?我不确定人们是否说htmlagility不支持xpath。我将解析 html 代码。
使用HtmlAgility的最简单方法 ->
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(string); //string contains the html code
var paragraphTags = doc.DocumentNode.SelectNodes("p"); //selects all p tags
for (int i = 0; i < paragraphTags.Count; i++) //loop through the p tags
{
String text = paragraphTags[i].InnerHtml;
//text has your paragraph content. use it here.
}