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 def APIinfo (phonenumber,apiN,debug): logging.captureWarnings(True) info = ["省","市","运营商","状态码"] if apiN == '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 if apiN == '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 if apiN == '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) 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[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
def main(): phonenumber = input() apiN = "1" debug = False print(APIinfo(phonenumber, "1", debug)) print(APIinfo(phonenumber, "2", debug)) print(APIinfo(phonenumber, "4", debug)) main()
|