源码以及程序下载跳转这里下载

闲来无事,练一下python
所以在网络上收集了几个API接口
写了一个python程序

准备工作

先找资料

1.Google一下
2.Bing
3.百度一下
4.搜狗搜索
5.Bilibili

得到了大量网站数据

#http://www.yulaoban.club/ca/
#https://api.mir6.com/doc/mobile.html
#https://cx.shouji.360.cn/
#http://tools.bugscaner.com/mobile/
#https://uutool.cn/phone-batch/
#https://www.qvdv.net/tools/qvdv-mobile.html
#https://www.haoshudi.com/
#https://shouji.bmcx.com/
#https://tool.lu/mobile/
#https://www.sogou.com/
#https://www.ip138.com/sj/
#https://cx.shouji.360.cn/?number=13556450000
#https://www.10086.cn/support/selfservice/ownership/
#https://m.ip138.com/mobile.html
#https://hao.360.com/sjgs.html
#https://www.wapi.cn/mobile_area.html
#https://236go.com/gongju/shoujihao/
#https://www.w3tool.com/query/
#https://www.wetools.com/shou-ji-hao
#https://www.lddgo.net/common/phone
#https://www.opengps.cn/Data/Phone/Index.aspx
#https://shoujidiqu.suinidai.cn/
#https://phone.265o.com/
#https://www.haoma123.com/dh/
#https://ip.cn/db.php
#https://guishudi.jihaoba.com/
#https://guishudi.hao86.com/
#https://sjhszdcx.tongchahao.com/
#https://www.tongchaba.com/sjhgsd
大量数据

下载python库

1
pip install requests

筛选可用API

发现以下3个API
1.”https://www.yulaoban.club/ca/aliyun/getMobileAddressByPhoneNum?phoneNum=“ + phonenumber
2.”https://api.mir6.com/api/mobile?mobile=“ +phonenumber+ “&saorao=true”
3.”https://shouji.bmcx.com/“ +phonenumber+ “__shouji/“
比较好用

开始搓键盘

1
2
import requests
import logging

第一个用于发送请求
第二个用于去除warming

1
def APIinfo (phonenumber,apiN,debug):

定义函数

1
logging.captureWarnings(True) 

去除python爬虫安全警告

1
info = ["省","市","运营商","状态码"]

初始化变量

1
2
response_API_1 = requests.get("https://www.yulaoban.club/ca/aliyun/getMobileAddressByPhoneNum?phoneNum=" + phonenumber,verify=False)
info_get = response_API_1.text

发送请求,随便输入一个手机号得到数据如下

1
{"code":100,"msg":"查询成功","extend":{"mobile":{"userId":0,"phoneNum":"13344550000","num":"13344550000","isp":"陕西电信CDMA卡","prov":"陕西","city":"西安","types":null,"cityCode":"029","areaCode":null,"zipCode":"132000\r\n","lng":null,"lat":null,"date":"2024-06-11 16:26:26.0"}}}

分析一下,截取数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
length_province = len("\"prov\":\"")
length_city = len("\"city\":\"")
length_supplier = len("\"isp\":\"")
ength_code = len("\"code\":")
position_province_beg = info_get.find("\"prov\":\"") + length_province
position_city_beg = info_get.find("\"city\":\"") + length_city
position_supplier_beg = info_get.find("\"isp\":\"") + length_supplier
position_code_beg = info_get.find("\"code\":") + length_code
position_province_end = info_get.find("\"", position_province_beg)
position_city_end = info_get.find("\"", position_city_beg)
position_supplier_end = info_get.find("\"", position_supplier_beg)
position_code_end = info_get.find(",", position_code_beg)
info[0] = info_get[position_province_beg : position_province_end]
info[1] = info_get[position_city_beg : position_city_end]
info[2] = info_get[position_supplier_beg : position_supplier_end]
info[3] = info_get[position_code_beg : position_code_end]

输出

1
return info

这些是基本思路

源码以及程序下载见Github

项目GitHub地址
程序GitHub下载
完整版请咨询作者
以下是源码:

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import requests
import logging # 用于去除warming
def APIinfo (phonenumber,apiN,debug):
logging.captureWarnings(True) # 去除python爬虫安全警告
info = ["省","市","运营商","状态码"]
if apiN == '1':
# API-1 哔哩哔哩UP
#print("******************API-1*******************")
response_API_1 = requests.get("https://www.yulaoban.club/ca/aliyun/getMobileAddressByPhoneNum?phoneNum=" + phonenumber,verify=False) # 发送请求
if debug == True:
print(response_API_1.text)
info_get = response_API_1.text

length_province = len("\"prov\":\"")
length_city = len("\"city\":\"")
length_supplier = len("\"isp\":\"")
length_code = len("\"code\":")

position_province_beg = info_get.find("\"prov\":\"") + length_province
position_city_beg = info_get.find("\"city\":\"") + length_city
position_supplier_beg = info_get.find("\"isp\":\"") + length_supplier
position_code_beg = info_get.find("\"code\":") + length_code

position_province_end = info_get.find("\"", position_province_beg)
position_city_end = info_get.find("\"", position_city_beg)
position_supplier_end = info_get.find("\"", position_supplier_beg)
position_code_end = info_get.find(",", position_code_beg)

info[0] = info_get[position_province_beg : position_province_end]
info[1] = info_get[position_city_beg : position_city_end]
info[2] = info_get[position_supplier_beg : position_supplier_end]
info[3] = info_get[position_code_beg : position_code_end]

if info[3] == "100": # 正确状态码
return info
elif info[3] == "200": # 错误状态码
info = [" ", " ", " ", " "]
info[3] = info_get[position_code_beg: position_code_end]
return info
#print("*****************************************")
if apiN == '2':
#API-2 米人
#print("******************API-2*******************")
response_API_2 = requests.get("https://api.mir6.com/api/mobile?mobile=" +phonenumber+ "&saorao=true",verify=False) # 发送请求
if debug == True:
print(response_API_2.text)
info_get = response_API_2.text

length_province = len("\"province\":\"")
length_city = len("\"city\":\"")
length_supplier = len("\"isp\":\"")
length_code = len("\"code\":")

position_province_beg = info_get.find("\"province\":\"") + length_province
position_city_beg = info_get.find("\"city\":\"") + length_city
position_supplier_beg = info_get.find("\"isp\":\"") + length_supplier
position_code_beg = info_get.find("\"code\":") + length_code

position_province_end = info_get.find("\"", position_province_beg)
position_city_end = info_get.find("\"", position_city_beg)
position_supplier_end = info_get.find("\"", position_supplier_beg)
position_code_end = info_get.find(",", position_code_beg)

info[0] = info_get[position_province_beg: position_province_end]
info[1] = info_get[position_city_beg: position_city_end]
info[2] = info_get[position_supplier_beg: position_supplier_end]
info[3] = info_get[position_code_beg: position_code_end]

if info[3] == "200": #正确状态码
return info
elif info[3] == "201": #错误状态码
info = [" ", " ", " ", " "]
info[3] = info_get[position_code_beg: position_code_end]
return info
#print("*****************************************")
if apiN == '4':
#API-4 便民网
# print("******************API-4*******************")
response_API_4 = requests.get("https://shouji.bmcx.com/" +phonenumber+ "__shouji/",verify=False) # 发送请求
info_get = response_API_4.text

length_province_city = len("归属地</td><td bgcolor=\"#FFFFFF\" align=\"center\" style=\"font-size:16px;\">.")
length_supplier = len("卡类型</td><td bgcolor=\"#FFFFFF\" align=\"center\" style=\"font-size:16px;\">.")

position_province_city = info_get.find("归属地</td>") + length_province_city
position_supplier = info_get.find("卡类型</td>") + length_supplier
position_code1 = str(info_get.find("404 Not Found"))
position_code2 = str(info_get.find("号码格式错误"))

position_province_city_div = info_get.find("<", position_province_city)
position_supplier_div = info_get.find("<", position_supplier)
#print(info_get)
supplier = info_get[position_supplier: position_supplier_div]
province_city = info_get[position_province_city: position_province_city_div]

info[0] = province_city[0:province_city.find(" ")]
info[1] = province_city[province_city.find(" "):len(province_city)]
info[2] = supplier

if debug == True and position_code1 == "-1" and position_code2 == "-1":
#print(info_get)
print(info_get[info_get.find("归属地</td>") : position_supplier_div])
print(position_code1)
print(position_code2)
elif debug == True and ((int(position_code2) >= 4400 and int(position_code2) <= 4600) or (int(position_code1) >= 50 and int(position_code1) <= 100)):
print(position_code1)
print(position_code2)
if position_code1 == "-1" and position_code2 == "-1": # 正确状态码
info[3] = position_code1
return info
elif (int(position_code2) >= 4400 and int(position_code2) <= 4600) or (int(position_code1) >= 50 and int(position_code1) <= 100): # 错误状态码
info = [" ", " ", " ", " "]
info[3] = position_code1
return info
# print("*****************************************")

def main():
phonenumber = input()
apiN = "1"
#debug = True
debug = False
print(APIinfo(phonenumber, "1", debug))
print(APIinfo(phonenumber, "2", debug))
print(APIinfo(phonenumber, "4", debug))
main()