【发布时间】:2013-05-09 17:15:33
【问题描述】:
我想从网页http://cslh.cz/delegace.html?id_season=2013
上的table class='nice'中解析日期、链接文本和链接href我创建了对象DelegationLink
public class DelegationLink
{
public string date { get; set; }
public string link { get; set; }
public string anchor { get; set; }
}
并将其与 LINQ 一起使用以创建 DelegationLink 列表
var parsedValues =
from table in htmlDoc.DocumentNode.SelectNodes("//table[@class='nice']")
from date in table.SelectNodes("tr//td")
from link in table.SelectNodes("tr//td//a")
.Where(x => x.Attributes.Contains("href"))
select new DelegationLink
{
date = date.InnerText,
link = link.Attributes["href"].Value,
anchortext = link.InnerText,
};
return parsedValues.ToList();
它只取一个日期列并将其与每一行中的链接列结合起来,但我只想简单地取表中的每一行并从该行获取日期、href 和 hreftext。 我是 LINQ 的新手,我使用 google 了 4 个小时,没有任何效果。感谢您的帮助。
【问题讨论】:
标签: c# linq html-agility-pack