python3.4 百度API接口


# -*- coding: utf-8 -*-
import urllib.request, json

url = 'http://apis.baidu.com/netpopo/illegaladdr/coord?lat=31.3004088721&lng=121.4849729860&range=2000&num=10'
add_header= {"apikey":"9a1bfb513e18XXXXXf48314508e"}
req = urllib.request.Request(url,headers=add_header)
resp = urllib.request.urlopen(req)
content = resp.read().decode('utf-8') 
#不用.decode('utf-8')會報錯the JSON object must be str, not 'bytes'
res = json.loads(content)
if(res):
    print(res)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM