1. 首页
  2. 程序生涯
  3. .NET

C#采集中国移动官网所有号码并筛选各类靓号

早几天要换号码,到移动营业厅去办说稍微看的顺眼的号码就要预存多少多少。我觉得好坑,但是在官网又找不到稍微顺眼的。无奈之下没办法写了这个采集软件。主要是想弥补官网搜索不方便的缺陷。下面上代码,比较简单:

        static void Main(string[] args)
        {
            string[] t = { "134", "135", "136", "137", "138", "139", "147", "150", "151", "152", "157", "158", "159", "182", "183", "187", "188" };
            string numberPattern = @"<a>.*?)""(.*?)</a>";

            for (int i = 0; i &lt; t.Length; i++)
            {
                int pageCount = 1;
                int page = 0;
                string postdata = "page={0}&amp;tdShopSelectionSuc.mobileType=0&amp;tdShopSelectionSuc.selectArea=0731&amp;tdShopSelectionSuc.selectAreaName=%E9%95%BF%E6%B2%99&amp;tdShopSelectionSuc.numberSeg={1}________&amp;tdShopSelectionSuc.numberRule=&amp;tdShopSelectionSuc.searchStr=___________&amp;tdShopSelectionSuc.endNumberRule=&amp;tdShopSelectionSuc.storedValueStart=&amp;tdShopSelectionSuc.storedValueEnd=&amp;tdShopSelectionSuc.compositor=2&amp;tdShopSelectionSuc.switchList=0&amp;retryQuery=yes&amp;numPriceSort=&amp;numSort=1&amp;pages.pageSize=15";
                string posturl = "https://www.hn.10086.cn/Shopping/selects/nos_queryPhoneInfo.action?timeStamp=" + ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000) + "" + new Random().Next(100, 999);

                for (int p = 0; p &lt; pageCount; p++)//翻页
                {
                    Console.WriteLine("正在获取{0}的所有号码,当前页码:{1}", t[i], page);
                    string html = HttpHelper.GetHtml(posturl, string.Format(postdata, page, t[i]), true);
                    if (html == "") { continue; }
                    if (pageCount == 1)
                    {
                        pageCount = int.Parse(Regex.Match(html, @"var pageCount = '(?.*?)';").Groups["value"].Value);
                    }
                    MatchCollection ms = Regex.Matches(html, numberPattern);
                    foreach (Match m in ms)
                    {
                        string number = m.Groups["value"].ToString();
                        if (!Exists(number))
                        {
                            DbHelperSQL.ExecuteSql("INSERT INTO Number(Number)VALUES('" + number + "')");
                        }
                        Console.WriteLine("号码:" + number);
                    }
                    page++;
                }
            }
            Console.WriteLine("结束.");
            Console.ReadKey();
        }

既然号码采集到数据库了,那就顺便写个SQL把心仪的号码筛选出来吧:
ABAB型:

select * from telephone where SUBSTRING(telenumber,8,2)=SUBSTRING(telenumber,10,2) and SUBSTRING(telenumber,8,1)!=SUBSTRING(telenumber,11,1);

AABB型:

select * from telephone where SUBSTRING(telenumber,8,1)=SUBSTRING(telenumber,9,1) and SUBSTRING(telenumber,10,1)=SUBSTRING(telenumber,11,1) and SUBSTRING(telenumber,8,1)!=SUBSTRING(telenumber,11,1);

AAAB型:

select * from telephone where SUBSTRING(telenumber,8,1)=SUBSTRING(telenumber,9,1) and SUBSTRING(telenumber,9,1)=SUBSTRING(telenumber,10,1) and SUBSTRING(telenumber,8,1)!=SUBSTRING(telenumber,11,1);

ABBB型:

select * from telephone where SUBSTRING(telenumber,9,1)=SUBSTRING(telenumber,10,1) and SUBSTRING(telenumber,11,1)=SUBSTRING(telenumber,10,1) and SUBSTRING(telenumber,8,1)!=SUBSTRING(telenumber,11,1);

AAAA型:

select * from telephone where SUBSTRING(telenumber,8,2)=SUBSTRING(telenumber,10,2) and SUBSTRING(telenumber,8,1)=SUBSTRING(telenumber,11,1);

好了,最后祝各位能找到自己心仪的号码。

原创文章,作者:锋哥,如若转载,请注明出处:https://www.fangsi.net/1031.html

发表评论

登录后才能评论

评论列表(3条)

  • Delta
    Delta 2016年7月23日 20:33

    短内容的了吧?!

  • 智慧商家
    智慧商家 2014年11月14日 10:13

    非常实用。值得推广

联系我们

在线咨询:点击这里给我发消息

邮件:service@fangsi.net

工作时间:周一至周五,9:30-18:30,节假日休息