1

我用谷歌搜索了我的问题,发现要解析的Html Agility Pack是. 但是没有好的例子,我不能用它来达到我的目的。我有一个,它有一个像这样的部分:htmlc#html document

<div class="pray-times-holder">
    <div class="pray-time">
        <div class="labels">
            Time1:</div>
        04:28:24
    </div>
    <div class="pray-time">
        <div class="labels">
            Time2:</div>
        06:04:41
    </div>
</div>

我想获得Time1and的值Time2。例如Time1有价值04:28:24Time2有价值06:04:41,我想得到这些价值。你能帮我吗?

4

2 回答 2

1
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);

var results = doc.DocumentNode
    .Descendants("div")
    .Where(n => n.Attributes["class"] != null && n.Attributes["class"].Value == "pray-time")
    .Select(n => n.InnerText.Replace("\r\n","").Trim())
    .ToArray();
于 2012-04-30T05:56:42.003 回答
1

此控制台应用程序代码:

 HtmlDocument doc = new HtmlDocument();
 doc.Load(yourHtml);
 foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//div[@class = 'labels']"))
 {
     Console.WriteLine(node.NextSibling.InnerText.Trim());
 }

将输出:

04:28:24
06:04:41
于 2012-05-03T07:10:54.290 回答