C#实现的中国移动官网手机号码采集器
程序员文章站
2023-12-15 17:13:22
早几天要换号码,到移动营业厅去办说稍微看的顺眼的号码就要预存多少多少。我觉得好坑,但是在官网又找不到稍微顺眼的。无奈之下没办法写了这个采集软件。主要是想弥补官网搜索不方便的...
早几天要换号码,到移动营业厅去办说稍微看的顺眼的号码就要预存多少多少。我觉得好坑,但是在官网又找不到稍微顺眼的。无奈之下没办法写了这个采集软件。主要是想弥补官网搜索不方便的缺陷。下面上代码,比较简单:
复制代码 代码如下:
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);
推荐阅读