我想从网上获得标题,描述。我用
var title= (from item in doc.DocumentNode.SelectNodes(
"//div[@class='section sectionMain recentNews']//a[@class='newsTitle']")
select item).ToList();
var des= (from item in doc.DocumentNode.SelectNodes(
"//div[@class='section sectionMain recentNews']//div[@class='newsText']")
select item).ToList();
现在,我想使用查询选择所有标题,描述如:
var data = (from item in doc.DocumentNode.SelectNodes(
"//div[@class='section sectionMain recentNews']") select new
{
title =..........., description =.......
}
答案 0 :(得分:0)
如果您不想在同一个循环中执行此操作,可以使用的方法之一是组合两个列表:
var title= (from item in doc.DocumentNode.SelectNodes(
"//div[@class='section sectionMain recentNews']//a[@class='newsTitle']")
select item).ToList();
var des= (from item in doc.DocumentNode.SelectNodes(
"//div[@class='section sectionMain recentNews']//div[@class='newsText']")
select item).ToList();
var items = title.Zip(des, (t, d) => new {Title = t, Description = v })
希望这会有所帮助:)