zoukankan      html  css  js  c++  java
  • Python获取城市天气,

    实现代码

    因此实现代码就可以写出来了!只需要获取网页中的元组数据。

    weather.py

    #coding:utf-8
    from urllib.parse import urlencode
    import requests
    import urllib
    import json#处理网页数据
     
    while True:#循环
        message = str(input("要查询的城市:"))
     
        url="https://api.iyk0.com/tq/?city={}".format(message)#获取用户输入的城市进行查询
        request=url
        re=requests.get(request)
        rep = re.json()
        '''
        获取网页中的响应的元组变量
        '''
        code = rep.get('code')
        msg = rep.get('msg')
        city = rep.get('city')
        up = rep.get('update_time')
        wea = rep.get('wea')
        wea_img = rep.get('wea_img')
        tem = rep.get('tem')
        tem_day = rep.get('tem_day')
        tem_night = rep.get('tem_night')
        win = rep.get('win')
        win_speed = rep.get('win_speed')
        win_meter = rep.get('win_meter')
        air = rep.get('air')
        time = rep.get('time')
        print('
    城市名字:',city)
        print('更新时间:',up)
        print('天气情况:',wea)
        print('时实温度:',tem)
        print('高温:',tem_day)
        print('低温:',tem_night)
        print('风向:',win)
        print('风力等:',win_speed)
        print('风速:',win_meter)
        print('空气质量:',air)
        print('当天日期,星期:',time,'
    ')
    lis = {'code':code,
           'msg':msg,
           'city':city,
           'update_time':up,
           'wea':wea,
           'wea_img':wea_img,
           'tem':tem,
           'tem_day':tem_day,
           'win':win,
           'win_speed':win_speed,
           'win_meter':win_meter,
           'air':air,
           'time':time,
           }
    #print(lis)
  • 相关阅读:
    5. JVM虚拟机栈
    4. 程序计数器
    3. JVM运行时数据区
    2. 类加载
    1. JVM体系结构
    SpringCloud 网关组件Gateway
    SpringCloud Hystrix断路器的基本使用
    SpringCloud Ribbon和Feign 的使用和源码分析
    反向代理的概念
    事务mysql
  • 原文地址:https://www.cnblogs.com/lyck/p/15240134.html
Copyright © 2011-2022 走看看