输入一个手机号后,结果如下:
接口调用了聚合数据官网(https://www.juhe.cn/)的“手机号码归属地”,仅用于交流学习。
import pytest
import requests
def test_mes():
phonenumber=input('请输入一个手机号:')
url = 'http://apis.juhe.cn/mobile/get'
headers={
'Content-Type':'application/x-www-form-urlencoded',
}
paramers={
'phone':phonenumber,
'key':'此处填写你自己的token',
'dtype':''
}
re=requests.get(url,headers=headers,params=paramers)
rej=re.json()
sf=rej['result']['province']
cs=rej['result']['city']
qh=rej['result']['areacode']
yb=rej['result']['zip']
khgs=rej['result']['company']
# print(rej)
print(end='\n')
print('网页状态码:{}'.format(re.status_code))
if len(sf) == 0:
print('省份:暂未获取到相关信息')
else:
print('省份:{}'.format(sf))
if len(cs) == 0:
print('城市:暂未获取到相关信息')
else:
print('城市:{}'.format(cs))
if len(qh) == 0:
print('区号:暂未获取到相关信息')
else:
print('区号:{}'.format(qh))
if len(yb)==0:
print('邮编:暂未获取到相关信息')
else:
print('邮编:{}'.format(yb))
if len(khgs) == 0:
print('卡号公司:暂未获取到相关信息')
else:
print('卡号公司:{}'.format(khgs))