第一種通過百度api找到電話號碼歸屬地
import requests
def get_location(phone_num):
path = 'http://mobsec-dianhua.baidu.com/dianhua_api/open/location'
result = requests.get(path, params={'tel': phone_num}, timeout=10).json()
return result
==>
{'response': {'18*********8': {'detail': {'area': [{'city': '九江'}], 'province': '江西', 'type': 'domestic', 'operator': '移動'}, 'location': '江西九江移動'}}, 'responseHeader': {'status': 200, 'time': 1545209598689, 'version': '1.1.0'}}
第二種,通過Python內置模塊phone
import phone #開始要下載phone模塊, pip install phone def get_location(phone_num): p = phone.Phone() result = p.find(phone_num) return result
==>
{'phone': '18770223348', 'province': '江西', 'city': '九江', 'zip_code': '332000', 'area_code': '0792', 'phone_type': '移動'}