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

时间:2021-05-20

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

复制代码 代码如下:
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:///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);

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章