手機號碼歸屬地查詢API,最多隻能查到省份。html
示例代碼:python
#-*- coding: utf-8 -*- #version:0.1 #note:該即用API能查詢電話號碼基本歸屬信息(只能查到省份) import urllib.request import json import collections url = "http://apistore.baidu.com/microservice/mobilephone?tel=" tel = input("輸入你想查詢的電話號碼:") url = url + tel #完整的URL result = urllib.request.urlopen(url).read().decode("utf-8") info = json.loads(result,object_pairs_hook=collections.OrderedDict) #json格式轉換爲python格式,並指定爲有序字典 if (info['errNum'] == -1): #查找失敗 print(info['errMsg']) else: #輸出天氣相關信息 print("你查詢的IP地址信息以下:") print("電話號碼:", info['retData']['telString']) print("省份:", info['retData']['province']) print("運營商:", info['retData']['carrier'])