今天发现百度有个API store,专门为开发者提供API服务,网址为:百度API Store。其中有“即用API体验专区”。什么是即用API呢?即用API是指开发者可以立即调用,无需注册付费,有调用次数限制的API服务。
下面是我用到其中的天气API进行的天气查询代码,天气API网页地址为天气API相关说明
#-*- coding: utf-8 -*-
#version:0.1
#note:该即用API接口只能查询当天天气信息,并且通过城市拼音输入进行城市参数传递
import urllib.request
import json
import collections
url = "http://apistore.baidu.com/microservice/weather?citypinyin="
city = input("输入你想查询城市的名称拼音:")
url = url + city #完整的URL
result = urllib.request.urlopen(url).read().decode("utf-8")
info = json.loads(r