zoukankan      html  css  js  c++  java
  • 数据采集器

    下载
    数据采集器,其实很简单,没有想像的那么复杂。
    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下载
     

  • 相关阅读:
    在泛型方法中返回泛型数组
    java泛型方法返回泛型结果
    hive -e和hive -f的区别(转)
    hive表批处理
    python网络编程——实现简单聊天
    python网络编程(转)
    python分布式编程(转)
    shell多线程之进程间通信(3)
    在xml文件中使用该控件
    Java文件中代码
  • 原文地址:https://www.cnblogs.com/rosanshao/p/1050241.html
Copyright © 2011-2022 走看看