百度api 找到当前电话号码归属地

第一种通过百度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': '移动'}

猜你喜欢

转载自www.cnblogs.com/52forjie/p/10144415.html