欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

C#实现的中国移动官网手机号码采集器

时间:2021-04-16 08:24:27|栏目:.NET代码|点击:

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

复制代码 代码如下:

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 data-original-title="" title="">.*?)""(.*?)</a>";
 
    for (int i = 0; i < t.Length; i++)
    {
        int pageCount = 1;
        int page = 0;
        string postdata = "page={0}&tdShopSelectionSuc.mobileType=0&tdShopSelectionSuc.selectArea=0731&tdShopSelectionSuc.selectAreaName=%E9%95%BF%E6%B2%99&tdShopSelectionSuc.numberSeg={1}________&tdShopSelectionSuc.numberRule=&tdShopSelectionSuc.searchStr=___________&tdShopSelectionSuc.endNumberRule=&tdShopSelectionSuc.storedValueStart=&tdShopSelectionSuc.storedValueEnd=&tdShopSelectionSuc.compositor=2&tdShopSelectionSuc.switchList=0&retryQuery=yes&numPriceSort=&numSort=1&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 < 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);

上一篇:C#动态代码生成控件后其他事件不能获取该控件值的解决方法

栏    目:.NET代码

下一篇:UnityShader3实现波浪效果

本文标题:C#实现的中国移动官网手机号码采集器

本文地址:http://www.codeinn.net/misctech/102300.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有