日期:2014-05-17 浏览次数:21010 次
int i = 0;
//创建一个htmlweb对象
HtmlWeb web = new HtmlWeb();
web.AutoDetectEncoding = true;
//读取内容返回HtmlAgilityPack.HtmlDocument对象
HtmlAgilityPack.HtmlDocument doc= web.Load(tBtxt_Url.Text.Trim());
HtmlNode node = doc.GetElementbyId("post_list");
//文件流
StreamWriter sw = File.CreateText("log.txt");
foreach (HtmlNode child in node.ChildNodes)
{
if (child.Attributes["class"] == null || child.Attributes["class"].Value != "post_item")
continue;
HtmlNode hn = HtmlNode.CreateNode(child.OuterHtml);
Write(sw, String.Format("推荐:{0}", hn.SelectSingleNode("//*[@class=\"diggnum\"]").InnerText));
Write(sw, String.Format("标题:{0}", hn.SelectSingleNode("//*[@class=\"titlelnk\"]").InnerText));
Write(sw, String.Format("介绍:{0}", hn.SelectSingleNode("//*[@class=\"post_item_summary\"]").InnerText));
Write(sw, String.Format("信息:{0}", hn.SelectSingleNode("//*[@class=\"post_item_foot\"]").InnerText));
string url = hn.SelectSingleNode("//*[@class=\"titlelnk\"]").Attributes["href"].Value.ToString();
Write(sw, String.Format("网址:{0}", url));