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 = @&quot;<a>.*?)&quot;&quot;(.*?)</a>&quot;;

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

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

    非常实用。值得推广