首页 > 编程 > C# > 正文

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

2020-01-24 02:18:18
字体:
来源:转载
供稿:网友

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

复制代码 代码如下:

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);

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表