您的位置:首页 > 其它

【干货】.NET开发通用组件发布(三) 简易数据采集组件

2014-04-05 01:09 477 查看

组件介绍和合作开发

  /article/5311178.html

简易数据采集组件

怎么说他是一个简易的数据采集组件呢?因为由于时间仓促,缺少从某位置开始到某位置结束这种模式的采集,暂且叫他简易数据采集组件吧。

直接进入主题。

准备

引用:MrHuo.Controls.Gather;

测试效果

1、我的测试代码是这样的:

using MrHuo.Controls.Gather;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Gather gather = new Gather()
{
RegexPattern = @"(?is)<a[^>]*?href=(['""]?)(?<url>[^'""\s>]+)\1[^>]*>(?<text>(?:(?!</?a\b).)*)</a>",
Url = "http://www.mrhuo.com"
};
gather.OnBeginCollect += gather_OnBeginCollect;
gather.OnCollecting += gather_OnCollecting;
gather.OnEndCollect += gather_OnEndCollect;
gather.OnError += gather_OnError;
gather.Collect();

Console.ReadLine();
}

static void gather_OnError(Exception obj)
{
Console.WriteLine("采集过程中发生错误:" + obj.Message);
}

static void gather_OnEndCollect()
{
Console.WriteLine("采集结束.");
}

static void gather_OnCollecting(System.Text.RegularExpressions.Match obj)
{
Console.WriteLine("正在采集:" + obj.Groups["text"].Value + "(" + obj.Groups["url"].Value + ")");
}

static void gather_OnBeginCollect()
{
Console.WriteLine("采集开始...");
}
}
}


2、采集结果:



3、关于采集过程中为什么不一次性输出结果,暂时没有更好的解决方法,所以暂无提供。

如有好的想法和建议,可以发送电子邮件到:admin@mrhuo.com,参与项目开发。

测试项目下载:

点击下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: