import sys
import urllib.request
import demjson
'''
python3 调用百度号码归属地查询接口显示中文结果
'''
def get_phone_location(number):
url = 'http://apis.baidu.com/apistore/mobilephoneservice/mobilephone?tel=%s' % number
req = urllib.request.Request(url)
req.add_header('apikey',' yourapikey') #红色字体部分填入您的apikey(it's free)
resp = urllib.request.urlopen(req)
content = resp.read()
return content
if __name__ == '__main__':
content = get_phone_location('15210983567')
resp=demjson.decode(content)
import urllib.request
import demjson
'''
python3 调用百度号码归属地查询接口显示中文结果
'''
def get_phone_location(number):
url = 'http://apis.baidu.com/apistore/mobilephoneservice/mobilephone?tel=%s' % number
req = urllib.request.Request(url)
req.add_header('apikey',' yourapikey') #红色字体部分填入您的apikey(it's free)
resp = urllib.request.urlopen(req)
content = resp.read()
return content
if __name__ == '__main__':
content = get_phone_location('15210983567')
resp=demjson.decode(content)
print(content)
print (resp)
结果如下: