C#實現(xiàn)的中國移動官網(wǎng)手機號碼采集器
更新時間:2014年10月31日 09:24:31 投稿:junjie
這篇文章主要介紹了C#實現(xiàn)的中國移動官網(wǎng)手機號碼采集器,本文先是采集號碼入庫,同時給出了篩選各類靚號的SQL語句,需要的朋友可以參考下
早幾天要換號碼,到移動營業(yè)廳去辦說稍微看的順眼的號碼就要預(yù)存多少多少。我覺得好坑,但是在官網(wǎng)又找不到稍微順眼的。無奈之下沒辦法寫了這個采集軟件。主要是想彌補官網(wǎng)搜索不方便的缺陷。下面上代碼,比較簡單:
復(fù)制代碼 代碼如下:
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型:
復(fù)制代碼 代碼如下:
select * from telephone where SUBSTRING(telenumber,8,2)=SUBSTRING(telenumber,10,2) and SUBSTRING(telenumber,8,1)!=SUBSTRING(telenumber,11,1);
AABB型:
復(fù)制代碼 代碼如下:
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型:
復(fù)制代碼 代碼如下:
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型:
復(fù)制代碼 代碼如下:
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型:
復(fù)制代碼 代碼如下:
select * from telephone where SUBSTRING(telenumber,8,2)=SUBSTRING(telenumber,10,2) and SUBSTRING(telenumber,8,1)=SUBSTRING(telenumber,11,1);
相關(guān)文章
C# 9 新特性——record的相關(guān)總結(jié)
這篇文章主要介紹了C# 9 新特性——record的相關(guān)總結(jié),幫助大家更好的理解和學(xué)習(xí)使用c# 9的新特性,感興趣的朋友可以了解下2021-02-02C#使用Socket快速判斷數(shù)據(jù)庫連接是否正常的方法
這篇文章主要介紹了C#使用Socket快速判斷數(shù)據(jù)庫連接是否正常的方法,涉及C#中socket操作的相關(guān)技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04