登录
原创

基于Python的免费手机号码归属地查询

专栏聚合数据JUHE.CN
发布于 2020-10-16 阅读 6028
  • Python
  • HTTP
  • HTTPS
  • 聚合
原创

一、开通接口

免费手机号码(段)归属地查询服务使用聚合数据提供的免费接口,每天可以100次免费调用。可以通过 https://www.juhe.cn/docs/api/id/11 注册及开通。

二、请求接口

#!/usr/bin/python
# -*- coding: utf-8 -*-

import urllib, urllib2, sys, json

reload(sys)
sys.setdefaultencoding('utf-8')

url = 'http://apis.juhe.cn/mobile/get'

params = {
    "phone": "13429667914",  # 查询的手机号码或手机号码前7位
    "key": "******",  # 您申请的API接口请求Key
}
querys = urllib.urlencode(params)

request = urllib2.Request(url, data=querys)
response = urllib2.urlopen(request)
content = response.read()
if (content):
    try:
        result = json.loads(content)
        error_code = result['error_code']
        if (error_code == 0):
            province = result['result']['province']
            city = result['result']['city']
            areacode = result['result']['areacode']
            zip = result['result']['zip']
            company = result['result']['company']
            print("省份:%s\n城市:%s\n区号:%s\n邮编:%s\n运营商:%s" % (province, city, areacode, zip, company))
        else:
            print("请求失败:%s %s" % (result['error_code'], result['reason']))
    except Exception as e:
        print("解析结果异常:%s" % e)
else:
    # 可能网络异常等问题,无法获取返回内容,请求异常
    print("请求异常")

三、请求结果

image.png

评论区

励志做一条安静的咸鱼,从此走上人生巅峰。

0

0

3

举报