C#實(shí)現(xiàn)的中國移動官網(wǎng)手機(jī)號碼采集器
早幾天要換號碼,到移動營業(yè)廳去辦說稍微看的順眼的號碼就要預(yù)存多少多少。我覺得好坑,但是在官網(wǎng)又找不到稍微順眼的。無奈之下沒辦法寫了這個采集軟件。主要是想彌補(bǔ)官網(wǎng)搜索不方便的缺陷。下面上代碼,比較簡單:
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}的所有號碼,當(dāng)前頁碼:{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("結(jié)束.");
Console.ReadKey();
}
既然號碼采集到數(shù)據(jù)庫了,那就順便寫個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);
相關(guān)文章
Unity3D實(shí)現(xiàn)虛擬按鈕控制人物移動效果
這篇文章主要為大家詳細(xì)介紹了Unity3D實(shí)現(xiàn)虛擬按鈕控制人物移動效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-02-02C# 9 新特性——record的相關(guān)總結(jié)
這篇文章主要介紹了C# 9 新特性——record的相關(guān)總結(jié),幫助大家更好的理解和學(xué)習(xí)使用c# 9的新特性,感興趣的朋友可以了解下2021-02-02ADO.NET實(shí)體數(shù)據(jù)模型詳細(xì)介紹
本文將詳細(xì)介紹ADO.NET實(shí)體數(shù)據(jù)模型,下面先看看簡單的單表的增刪改查操作,然后再看多表的關(guān)聯(lián)查詢,帶參數(shù)查詢等2012-11-11opencvsharp瑕疵檢測的實(shí)現(xiàn)示例
本文主要介紹了opencvsharp瑕疵檢測的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05C#使用Socket快速判斷數(shù)據(jù)庫連接是否正常的方法
這篇文章主要介紹了C#使用Socket快速判斷數(shù)據(jù)庫連接是否正常的方法,涉及C#中socket操作的相關(guān)技巧,非常具有實(shí)用價值,需要的朋友可以參考下2015-04-04