posts - 12, comments - 46, trackbacks - 1, articles - 4
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

数据采集器

Posted on 2008-01-23 16:20 rosanshao 阅读(571) 评论(3)  编辑 收藏
下载
数据采集器,其实很简单,没有想像的那么复杂。
1使用HttpWebRequest或者WebClient获取数据
2 使用正则表达式获取你想要的数据
现在将相关代码贴出来

public static string GetHtml(string begin, string end, string content)
        {
            Regex reg = new Regex(begin + "((.*?\\n?)*?)" + end);
            Match match = reg.Match(content);

            if (match != Match.Empty)
            {
                //content = content.Replace(match.Groups[1].ToString(), string.Empty);
                return match.Groups[1].ToString();
            }
            else
            {
                return string.Empty;
            }
        }
        public static StringCollection GetHtmls(string begin, string end, string content)
        {
            Regex reg = new Regex(begin + "((.*?\\n?)*?)" + end);
            MatchCollection  matches = reg.Matches(content);
            StringCollection list=new StringCollection();
            foreach(Match match in matches)           
            {
                if (match != Match.Empty)
                {
                    list.Add(match.Value);
                }
            }
            return list;
        }

示例:获取代理器Ip下载
 

Feedback

#1楼    回复  引用    

2008-01-23 16:44 by QH [未注册用户]
请问:如何使用呢?
那三个参数是什么意思呀?
content 是不是 获取的源文件呀?

#2楼    回复  引用    

2008-01-23 16:51 by 002554 [未注册用户]
是的,意思就是,要获取Content中,Begin和End间的内容。

#3楼    回复  引用  查看    

2008-01-23 19:19 by 江南白衣      
晕,怎么会跳转到别的网站上去?

标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2008-01-23 16:43 编辑过


相关链接: