VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > C#编程 >
  • C#教程之亲手撸码,爬取 手机号码归属地最新数据(201911)(2)

开始获取数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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}] ......");
    }
}
相关教程