聚合数据免费天气预报API接口查询——基于Python

一、开通接口
天气预报接口服务使用的聚合数据提供的免费接口,每天可以100次免费调用。可以通过https://www.juhe.cn/docs/api/id/73注册及开通。

二、Python2.x调用示例

#!/usr/bin/python
# -*- coding: utf-8 -*-

import urllib, urllib2, sys, json

reload(sys)
sys.setdefaultencoding('utf-8')

url = 'http://apis.juhe.cn/simpleWeather/query'

params = {
   
    "city": "北京",  # 查询天气的城市名称,如:北京、苏州、上海
    "key": "xxxxxxxx",  # 您申请的接口API接口请求Key
}
querys = urllib.urlencode(params)

request = urllib2.Request(url, data=querys)
response = urllib2.urlopen(request)
content = response.read()
if (content):
    try:
        result = json.loads(content)
        error_code = result['error_code']
        if (error_code == 0):
            temperature = result['result']['realtime'][
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值