手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#实现的中国移动官网手机号码采集器
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 data-original-title="" title="">.*"(.*";

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" + ((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#实现的中国移动官网手机号码采集器】相关文章:

C#软件注册码的实现代码

C#实现图片分割方法与代码

C# WORD操作实现代码

C#中通过API实现的打印类 实例代码

C#中38个常用运算符的优先级的划分和理解

C# 撒列实现关键字过滤的实例

C#如何取硬件标志

C#调用和实现WebService,纯手工打造!

C#中除去所有在HTML元素中标记

C#垃圾回收机制的详细介绍

精品推荐
分类导航