【发布时间】:2020-03-08 01:11:40
【问题描述】:
我正在尝试获取此标签的文本值:
<a href="item?id=22513425">67&nbsp;comments</a>
所以我试图从中获得“67”。但是没有定义类或 ID。
我已经做到了这一点:
IEnumerable<HtmlNode> commentsNode = htmlDoc.DocumentNode.Descendants(0).Where(n => n.HasClass("subtext"));
var storyComments = commentsNode.Select(n =>
n.SelectSingleNode("//a[3]")).ToList();
这只给我“cmets”就够烦了。
我不能使用href id,因为这些项目很多,所以我不能硬编码href
我怎样才能提取数字呢?
【问题讨论】: