日期:2014-05-20 浏览次数:20729 次
var titles = from row in GetHtml("http://bbs.csdn.net/forums/DotNET/").DocumentNode.SelectSingleNode("//table[@class='table_list parent_forum ']").Elements("tr").Skip(1)
let td = row.Element("td")
where td != null
let a = td.Descendants("a").FirstOrDefault()
where a != null
select new
{
href = a.Attributes["href"].Value,
text = a.InnerText
};
var pages = from t in titles.AsParallel().WithDegreeOfParallelism(64)
where t.href != null
let path = "http://bbs.csdn.net" + t.href
let subQuery = from nick in GetHtml(path).DocumentNode.SelectNodes("//span[@class='name2nick']")
where nick.InnerText == "sp1234"
select nick
where subQuery.Any()
select new
{
title = t.text,
href = path
};
var results = pages.ToList();
from t in titles.AsParallel().WithDegreeOfParallelism(64)改为简单的
from t in titles时,可以测试一下顺序执行需要多少时间。