HtmlAgilityPack 解析HTMl 真不错
来源:互联网 发布:2016年网络新书排行榜 编辑:程序博客网 时间:2024/05/20 08:44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using HtmlAgilityPack;
namespace DemoCnBlogs
{
class Program
{
static void Main(string[] args)
{
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load("http://www.cnblogs.com/pick/");
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);
///如果用child.SelectSingleNode("//*[@class=\"titlelnk\"]").InnerText这样的方式查询,是永远以整个document为基准来查询,
///这点就不好,理应以当前child节点的html为基准才对。
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));
Write(sw, "----------------------------------------");
}
sw.Close();
Console.ReadLine();
}
static void Write(StreamWriter writer, string str)
{
Console.WriteLine(str);
writer.WriteLine(str);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using HtmlAgilityPack;
namespace DemoCnBlogs
{
class Program
{
static void Main(string[] args)
{
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load("http://www.cnblogs.com/pick/");
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);
///如果用child.SelectSingleNode("//*[@class=\"titlelnk\"]").InnerText这样的方式查询,是永远以整个document为基准来查询,
///这点就不好,理应以当前child节点的html为基准才对。
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));
Write(sw, "----------------------------------------");
}
sw.Close();
Console.ReadLine();
}
static void Write(StreamWriter writer, string str)
{
Console.WriteLine(str);
writer.WriteLine(str);
}
}
}
- HtmlAgilityPack 解析HTMl 真不错
- HTML解析利器HtmlAgilityPack
- HTML解析利器HtmlAgilityPack
- HTML解析利器HtmlAgilityPack
- htmlagilitypack解析Html
- HTML解析利器HtmlAgilityPack
- HTML解析利器HtmlAgilityPack
- HTML解析利器HtmlAgilityPack
- HTML解析利器HtmlAgilityPack
- HTML解析利器HtmlAgilityPack
- HTML解析利器HtmlAgilityPack
- HTML解析利器HtmlAgilityPack
- html解析器 HtmlAgilityPack
- HTML解析利器HtmlAgilityPack
- HtmlAgilityPack 解析HTML利器
- 使用HtmlAgilityPack解析html
- WindowsPhone使用HtmlAgilityPack解析HTML
- HTML解析组件HtmlAgilityPack使用
- mono for andoid之参数传递
- 一句代码让程序崩溃
- 虚函数的调用
- java Set 的一些总结
- 今年
- HtmlAgilityPack 解析HTMl 真不错
- 黑马程序员-C#编程基础之结构-学习笔记
- C#程序中进行FTP上传下载时出现的问题
- Start/Stop the Workflow Services in Oracle Apps
- JS 隔行变色
- VC++对话框中添加状态栏的方法
- dataGrid表头显示
- 软件工程:PG.SE.PL.PM角色定义
- Android APK反编译详解(附图) .