某天,某部门负责人小姐姐:要在订单中识别收货人手机号码归属地,这样可以参考判断该客户是否为恶意下单。
搬砖君:可以,有两种方案;
一、网上买个api接口(需要rmb支持);
二、找个手机归属地库(免费,有可能不是最新);
小姐姐:申请rmb,估计领导不会签字,那就免费的吧。
搬砖君:好吧,(此时心中一万个。。。(你们懂的));
于是某度搜索 手机号码归属地最新数据库 排名第一的居然是园子里的高手,瞬间兴奋起来,
打开链接看到 github ,心想这下不要去撸码找数据了。结果翻遍每个文件夹只有查询方法,却没有库。
再往下看原来库是有 购买 链接,还有升级链接。看来这路走不通了。
再翻了下某度的其它搜索结果,要么不最新,要么收费,要么就是登录需要积分下载。
心想去找个api接口把他的数据撸出来就好了。 继续某度 手机号码归属地查询api接口 ,
经过测试,比对,找了4个可用而且可信度比较高的。
开始撸码【抱歉,数据源和数据入库 画面请各位小伙伴自行脑补】:
private static list<string> mobilelist = new list<string>(); // 中途中断后, 已经存在的手机号段列表 using (sqlconnection conn = new sqlconnection(constr)) { if (mobilelist.count == 0) { string temp_sql = $"select [mobile] from [app_mobile_20191113]"; using (sqlcommand command = new sqlcommand(temp_sql, conn)) { command.commandtype = system.data.commandtype.text; if (conn.state == connectionstate.closed) conn.open(); using (sqldatareader dreader = command.executereader()) { while (dreader.read()) { mobilelist.add(dreader[0].tostring()); } } } } }
一个号码段前三位一个线程
list<task> tasklist = new list<task>(); taskfactory taskfactory = new taskfactory(); // 从手机前3位 130 开始 至 199 结束 for (int i = 130; i < 200; i++) { int mobile_no = i; tasklist.add(taskfactory.startnew(() => { console.writeline($"{mobile_no} = {thread.currentthread.managedthreadid}"); get(mobile_no); })); } task.waitall(tasklist.toarray());
开始获取数据
static void get(int start_no) { int start_mobile = int.parse($"{start_no}0000"); int end_mobile = int.parse($"{start_no}9999"); // 获取某开头下的所有号码段 如: 1300000 - 1309999 for (int i = start_mobile; i <= end_mobile; i++) { if (mobilelist.contains(i.tostring())) continue; //已经存在的号码 int code = new random().next(1000, 9999); // 随机手机号码最后4位 string mobile = $"{i}{code}"; //获取数据 【抱歉,数据来源画面请各位小伙伴自行脑补】 modelmobile model = get1(mobile); // 数据源1 if (!model.queryresult || string.isnullorwhitespace(model.province)) model = get2(mobile); // 数据源2 if (!model.queryresult || string.isnullorwhitespace(model.province)) model = get3(mobile); // 数据源3 if (!model.queryresult || string.isnullorwhitespace(model.province)) model = get4(mobile); // 数据源4 //获取成功后入库【入库画面请各位小伙伴自行脑补】 if (model.queryresult) { if (save_data(model)) console.writeline($" {thread.currentthread.managedthreadid}. success \t{i} = {model.province} {model.city} ({model.corp}) [{model.source}] ......"); else console.writeline($" {thread.currentthread.managedthreadid}. savefail \t{i} = {model.province} {model.city} ({model.corp}) [{model.source}] ......"); } else console.writeline($" {thread.currentthread.managedthreadid}. fail \t{i} = {model.message} [{model.source}] ......"); } }
运行效果:
爬完所有号段后,数据总 442245 条,比某度排第一园子里的高手还要多。
只要源数据正常,这库还可以一直正常升级。
撸码完成,敢快去通知小姐姐,已经可以正常调用了。