我正在使用CsQuery解析一些wordpress博客文章,对它们进行一些文本聚类分析。我想从相关的<p>
节点中删除文本。
var content = dom["div.entry-content>p"];
if (content.Length == 1)
{
System.Diagnostics.Debug.WriteLine(content[0].InnerHTML);
System.Diagnostics.Debug.WriteLine(content[0].InnerText);
}
在其中一个帖子中,InnerHTML
看起来是这样的:
An MIT Europe project that attempts to <a title="Wired News: Gizmo Puts Cards
on the Table" href="http://www.wired.com/news/technology/0,1282,61265,00.html?
tw=rss.TEK">connect two loved ones seperated by distance</a> through the use
of two tables, a bunch of RFID tags and a couple of projectors.
和相应的InnerText
像这样
MIT Europe的一个项目,试图通过使用两个表,一堆射频识别标签和几个投影仪。
。内部文本缺少锚文本。我可以自己解析HTML,但我希望有一种方法让CsQuery给我
麻省理工学院欧洲项目,试图连接两个爱的人间隔距离通过使用两张桌子,一堆RFID标签和几个投影仪。
(我的斜体)。我该怎么得到这个?
string result = dom["div.entry-content>p"].Text();
文本函数将包括p以下的所有内容,包括p标签。
尝试使用HtmlAgilityPack
using HAP = HtmlAgilityPack;
...
var doc = new HAP.HtmlDocument();
doc.LoadHtml("Your html");
var node = doc.DocumentNode.SelectSingleNode(@"node xPath");
Console.WriteLine(node.InnerText());
xPath是页面上节点的路径。
例如:在Google Chrome中,按F12并选择您的节点,右键单击并选择"复制xPath"
这一主题标题xPath://* [@ id = " question-header "]/h1/