-
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="">.*?)""(.*?)</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);
栏目列表
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比