手机归属地的json数据爬取
import requests
import json
class Sjgsd(object):
def __init__(self):
self.phone=''
def sjgsd(self):
while 1:
self.phone=input('请输入您要查询的手机号码:')
url='http://apis.juhe.cn/mobile/get?phone=%s&key=89baea64806cf2020fed945e44a65dd2'%self.phone
rs=requests.get(url)
phone_info=json.loads(rs.text)
msg=phone_info['reason']
if msg=='Return Successd!':
result=phone_info['result']
province=result['province']
city=result['city']
areacode=result['areacode']
zip=result['zip']
company=result['company']
print('省份:%s\n城市:%s\n区域编码:%s\n邮编:%s\n公司:%s'%(province,city,areacode,zip,company))
else:
print('您输入的号码无效!')
break
if __name__=='__main__':
sj=Sjgsd()
sj.sjgsd()