国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

python+pyecharts+flask+爬蟲實現(xiàn)實時天氣查詢可視化

這篇具有很好參考價值的文章主要介紹了python+pyecharts+flask+爬蟲實現(xiàn)實時天氣查詢可視化。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、項目簡介

本項目使用python語言編寫,采用Flaskweb框架來實現(xiàn)前后端交互,利于開發(fā),維護,前端使用Html和jQuery處理事件,發(fā)送數(shù)據(jù)等,后端采用requests庫,BeautifulSoup庫實現(xiàn)爬取中國氣象局的數(shù)據(jù),清洗轉(zhuǎn)化成對應表格數(shù)據(jù)格式,再使用pyecharts繪制圖形,返回給前端頁面實現(xiàn)實時展示,注意運行本項目需要聯(lián)網(wǎng)?。?!

二、項目演示

輸入你要查詢的城市,點擊搜索即可,由于網(wǎng)速,pyecharts的圖形渲染等因素,圖形展示需等待幾秒才出現(xiàn)。

pyecharts+flask,python,flask,爬蟲,echarts

注意水球圖的渲染有時出不來,可多次點擊搜索即可,我是這樣的啦!?。ㄅcpyecharts圖形渲染有關(guān))

pyecharts+flask,python,flask,爬蟲,echarts

?pyecharts+flask,python,flask,爬蟲,echartspyecharts+flask,python,flask,爬蟲,echarts

?三、項目的實現(xiàn)

?1.項目包結(jié)構(gòu)展示:

?pyecharts+flask,python,flask,爬蟲,echarts

其中app.py為項目的啟動文件及路由,templates包存放前端頁面的,service包存放后端邏輯代碼venv為排除目錄(沒啥用可不創(chuàng)建),包可以自己標記為對用的資源目錄,我沒有使用flask模板創(chuàng)建,而是自己標記的pyecharts+flask,python,flask,爬蟲,echarts

創(chuàng)建好包就可以書寫代碼啦?。。?/p>

2.Service包代碼編寫

?2.1.WeatherDate(爬取天氣數(shù)據(jù))
import sys
import pandas as pd
import requests
from bs4 import BeautifulSoup

# 請求頭可寫,但我看沒報錯,就沒寫
headers = {
    'user-agent': '',
    'Cookie': ''
}

# 列表劃分,例如[1,2,3,4]=>[[1,2],[3,4]],目的適應pyecharts數(shù)據(jù)
def chunk_list(lst, size):
    return [lst[i:i + size] for i in range(0, len(lst), size)]


# 數(shù)據(jù)圖一的部分數(shù)據(jù)列表
def data1(soup):
    seven_dayList = [i.text.strip().replace(' ', '').replace('\n', '') for i in soup.select('.day-item')]
    temp = []
    # 數(shù)據(jù)清洗
    j = 0
    for i in seven_dayList:
        if j % 10 == 0:
            temp.append('2023年' + i[3:5] + '月' + i[6:] + '日')
            temp.append(i[:3])
        if j % 10 == 5:
            temp.append(i[:3])
            temp.append(i[3:])
        if i != '' and j % 10 != 0 and j % 10 != 5:
            temp.append(i)
        j += 1
    # 數(shù)據(jù)格式對應表格
    seven_dayLists = chunk_list(temp, 10)
    return seven_dayLists


# 圖二表格數(shù)據(jù)列表
def data2(soup):
    total_list = [i.text.strip() for i in soup.select('.hour-table td')]
    temp = []
    for i in total_list:
        if i != '' and i != '天氣':
            temp.append(i)
    # 時間
    time_list = []
    # 氣溫
    temperature_list = []
    # 降水
    rainfall_list = []
    # 風速
    windspeed_list = []
    # 風向
    winddirection_list = []
    # 氣壓
    pressure_list = []
    # 濕度
    humidity_list = []
    # 云量
    cloud_list = []
    categories = ['時間', '氣溫', '降水', '風速', '風向', '氣壓', '濕度', '云量']
    current_category = None
    for item in temp:
        if item in categories:
            current_category = item
        else:
            if current_category == '時間':
                time_list.append(item)
            elif current_category == '氣溫':
                temperature_list.append(item)
            elif current_category == '降水':
                rainfall_list.append(item)
            elif current_category == '風速':
                windspeed_list.append(item)
            elif current_category == '風向':
                winddirection_list.append(item)
            elif current_category == '氣壓':
                pressure_list.append(item)
            elif current_category == '濕度':
                humidity_list.append(item)
            elif current_category == '云量':
                cloud_list.append(item)
    # 切割
    return chunk_list(time_list, 8), chunk_list(temperature_list, 8), chunk_list(rainfall_list, 8), \
           chunk_list(windspeed_list, 8), chunk_list(winddirection_list, 8), chunk_list(pressure_list, 8), \
           chunk_list(humidity_list, 8), chunk_list(cloud_list, 8)


# 數(shù)據(jù)轉(zhuǎn)換(表格所需)
def data_change(seven_dayList, temperature_list, windspeed_list, pressure_list, humidity_list, cloud_list):
    # 將seven_dayList切出最高氣溫和最低氣溫
    data_list = []
    high_temperature = []
    low_temperature = []
    for i in seven_dayList:
        data_list.append(i[0])
        high_temperature.append(eval(i[5][:-1]))
        low_temperature.append(eval(i[6][:-1]))
    # 將temperature_list轉(zhuǎn)化為數(shù)字
    temperature_lists = []
    for i in temperature_list:
        temperature_lists.append(eval(i[:-1]))
    # 將windspeed_list轉(zhuǎn)化為數(shù)字
    windspeed_lists = []
    for i in windspeed_list:
        windspeed_lists.append(eval(i[:-3]))
    # 將pressure_list轉(zhuǎn)化為數(shù)字
    pressure_lists = []
    for i in pressure_list:
        pressure_lists.append(eval(i[:-3]))
    # 將humidity_list轉(zhuǎn)化為數(shù)字
    humidity_lists = []
    for i in humidity_list:
        humidity_lists.append(round(eval(i[:-1]) / 100, 3))
    # 將cloud_list轉(zhuǎn)化為數(shù)字
    cloud_lists = []
    for i in cloud_list:
        cloud_lists.append(eval(i[:-1]))
    return data_list, high_temperature, low_temperature, temperature_lists, \
           windspeed_lists, pressure_lists, humidity_lists, cloud_lists

# 關(guān)鍵代碼(通過城市名字找到cityinfo.xls文件對應url后的對應代碼)
def weather_data(city):
    try:
        data = pd.read_excel('F:\PythonXM\WeatherXM\static\cityinfo.xls', index_col='城市名稱')
        code = data.loc[city]['對應代碼']
    except Exception as e:
        print('輸入的城市錯誤,請重新輸入!')
        print(e)
        sys.exit()
    # 對應城市的url地址
    url = 'https://weather.cma.cn/web/weather/{}.html'.format(code)
    res = requests.get(url=url, headers=headers).content.decode('utf-8')
    soup = BeautifulSoup(res, 'lxml')
    seven_dayList = data1(soup)
    time_list, temperature_list, rainfall_list, windspeed_list, winddirection_list, \
    pressure_list, humidity_list, cloud_list = data2(soup)

    # 測試數(shù)據(jù)(上面是所有數(shù)據(jù)可自行選取,清洗)

    # print(seven_dayList)
    # print(time_list)
    # print(temperature_list)
    # print(rainfall_list)
    # print(windspeed_list)
    # print(winddirection_list)
    # print(pressure_list)
    # print(humidity_list)
    # print(cloud_list)

    # 只取當日數(shù)據(jù)和所需表格數(shù)據(jù)
    data_list, high_temperature, low_temperature, temperature_lists, \
    windspeed_lists, pressure_lists, humidity_lists, cloud_lists = \
        data_change(seven_dayList, temperature_list[0], windspeed_list[0],
                    pressure_list[0], humidity_list[0], cloud_list[0])

    # 測試數(shù)據(jù)
    # print(data_list)
    # print(time_list)
    # print(high_temperature)
    # print(low_temperature)
    # print(temperature_lists)
    # print(windspeed_lists)
    # print(pressure_lists)
    # print(humidity_lists)
    # print(cloud_lists)

    return seven_dayList, data_list, high_temperature, low_temperature, time_list[0], temperature_lists, \
           windspeed_lists, pressure_lists, humidity_lists, cloud_lists


if __name__ == '__main__':
    weather_data('張家界')

思路:其中weather_data函數(shù)為關(guān)鍵,其他的為數(shù)據(jù)清洗,這里感謝gitee上的一位博主(忘記叫啥了,哈哈)的cityinfo.xls文件,通過輸入的城市,找到對應的尾部代號,進而請求該城市頁面的數(shù)據(jù),沒這文件可以使用selenium去獲?。ㄟ@也是一種思路),不過會很慢?。?strong>文件在下面?。。。?/span>

pyecharts+flask,python,flask,爬蟲,echarts

cityinfo.xls文件:

?pyecharts+flask,python,flask,爬蟲,echarts

遇到的問題點:pandas在讀取包文件時,使用相對路徑'../static/cityinfo.xls',在下面的測試沒問題,但當項目運行時老是找不到該文件路徑,故寫的絕對路徑才得以解決,至于原因,暫未知,有知道歡迎在下面討論!

?2.2.DataShow(數(shù)據(jù)的可視化圖表)
from pyecharts.globals import SymbolType
from pyecharts.options import ComponentTitleOpts
from WeatherXM.service.weatherData import weather_data
import pyecharts.options as opts
from pyecharts.charts import Line, Liquid, EffectScatter, Gauge, Timeline, Scatter, Page, Grid, Pie
from pyecharts.components import Table


# # 測試數(shù)據(jù)獲取
# seven_dayList, data_list, high_temperature, low_temperature, time_list, temperature_lists, \
# windspeed_lists, pressure_lists, humidity_lists, cloud_lists = weather_data('上海')

# 標題
def tab(name, color) -> Pie:  # 作為標題
    tab = (
        Pie(init_opts=opts.InitOpts(width='100%',height='100px')).
        set_global_opts(title_opts=opts.TitleOpts(title=name, pos_left='center', pos_top='center',
                                                  title_textstyle_opts=opts.TextStyleOpts(color=color, font_size=35))))
    return tab


# 需求一:當日溫度變化曲線
def temperature_line(hour, temperature) -> Line:
    line = (
        Line(init_opts=opts.InitOpts(width='50%'))
        .add_xaxis(hour)
        .add_yaxis("溫度", temperature, is_connect_nones=True)
        .set_series_opts(label_opts=opts.LabelOpts(formatter='{@[1]}℃'))
        .set_global_opts(title_opts=opts.TitleOpts(title="當日平均溫度變化曲線"), yaxis_opts=opts.AxisOpts(
            type_='value',
            axislabel_opts=opts.LabelOpts(formatter="{value} ℃")))
    )
    return line


# 需求二:當日平均濕度
def humidity_liquid(humidity) -> Liquid():
    liquid = (
        Liquid(init_opts=opts.InitOpts(width='50%'))
        # .add("lq", [0.6, 0.7])
        .add("濕度", humidity, is_outline_show=False)
        .set_global_opts(title_opts=opts.TitleOpts(title="當日平均濕度"))
    )
    return liquid


# 需求三:當日風速變化:
def windspeed_effectScatter(hour, windspeed) -> EffectScatter:
    effectScatter = (
        EffectScatter(init_opts=opts.InitOpts(width='50%'))
        .add_xaxis(hour)
        .add_yaxis("風速", windspeed, symbol=SymbolType.ARROW)
        .set_series_opts(label_opts=opts.LabelOpts(formatter='{@[1]}m/s'))
        .set_global_opts(title_opts=opts.TitleOpts(title="當日風速變化"), yaxis_opts=opts.AxisOpts(
            type_='value',
            axislabel_opts=opts.LabelOpts(formatter="{value}m/s")))
    )
    return effectScatter


# 需求三:當日最高最低氣溫變化曲線
def high_low_temperature_line(hour, high_temperature, low_temperature) -> Line:
    line = (
        Line(init_opts=opts.InitOpts(width='50%'))
        .add_xaxis(xaxis_data=hour)
        .add_yaxis(
            series_name="白天氣溫",
            y_axis=high_temperature,
            markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_="max", name="最大值"),
                    opts.MarkPointItem(type_="min", name="最小值"),
                ]
            ),
            markline_opts=opts.MarkLineOpts(
                data=[opts.MarkLineItem(type_="average", name="平均值")]
            ),
        )
        .add_yaxis(
            series_name="夜晚氣溫",
            y_axis=low_temperature,
            markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_="max", name="最大值"),
                    opts.MarkPointItem(type_="min", name="最小值"),
                ]
            ),
            markline_opts=opts.MarkLineOpts(
                data=[opts.MarkLineItem(type_="average", name="平均值")]
            ),
        )
        .set_series_opts(label_opts=opts.LabelOpts(formatter='{@[1]}℃'))
        .set_global_opts(
            title_opts=opts.TitleOpts(title="七日最高最低氣溫變化曲線"),
            tooltip_opts=opts.TooltipOpts(trigger="axis"),
            toolbox_opts=opts.ToolboxOpts(is_show=True),
            xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False),
            yaxis_opts=opts.AxisOpts(
                type_='value',
                axislabel_opts=opts.LabelOpts(formatter="{value} ℃"))
        )
    )
    return line


# 需求四:當日氣壓
def pressure_gauge(hour, pressure) -> Timeline:
    tl = Timeline(init_opts=opts.InitOpts(width='50%'))
    for i in range(len(hour)):
        gauge = (
            Gauge()
            .set_global_opts(title_opts=opts.TitleOpts(title="氣壓儀表盤"),
                             legend_opts=opts.LegendOpts(is_show=False))
            .add(min_=0, max_=1500, data_pair=[(f'{hour[i]}時氣壓', pressure[i])], series_name=f'氣壓',
                 detail_label_opts=opts.GaugeDetailOpts(formatter="{value}hPa"))
        )
        tl.add(gauge, '{}'.format(hour[i]))
    return tl


# 需求五:當日云量散點圖
def cloud_scatter(hour, cloud) -> Scatter:
    scatter = (
        Scatter(init_opts=opts.InitOpts(width='50%'))
        .add_xaxis(hour)
        .add_yaxis("云量", cloud)
        .set_series_opts(label_opts=opts.LabelOpts(formatter='{@[1]}%'))
        .set_global_opts(
            title_opts=opts.TitleOpts(title="當日云量散點圖"),
            visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),
            yaxis_opts=opts.AxisOpts(
                type_='value',
                axislabel_opts=opts.LabelOpts(formatter="{value}%"))
        )
    )
    return scatter


# 需求六:七日天氣預報表格
def seven_day_table(seven_day) -> Table:
    headers = ['日期', '星期', '白天天氣', '白天風向', '白天風力', '白天氣溫', '晚上氣溫', '晚上天氣', '晚上風向', '晚上風力']
    table = (
        Table()
        .add(headers, seven_day)
        .set_global_opts(
            title_opts=ComponentTitleOpts(title="七日天氣預報")
        )
    )
    return table


# 需求匯總
def get_chart(city):
    # 數(shù)據(jù)獲取
    seven_dayList, data_list, high_temperature, low_temperature, time_list, temperature_lists, \
    windspeed_lists, pressure_lists, humidity_lists, cloud_lists = weather_data(city)
    page = Page(layout=Page.SimplePageLayout)
    page.add(
        tab(f'{city}未來七日天氣預報', '#000000'),
        temperature_line(time_list, temperature_lists),
        high_low_temperature_line(data_list, high_temperature, low_temperature),
        humidity_liquid(humidity_lists),
        pressure_gauge(time_list, pressure_lists),
        windspeed_effectScatter(time_list, windspeed_lists),
        cloud_scatter(time_list, cloud_lists),
        seven_day_table(seven_dayList)
    )
    # page.render("page_draggable_layout.html")
    return page


# def get_chart(city):
#     # 數(shù)據(jù)獲取
#     seven_dayList, data_list, high_temperature, low_temperature, time_list, temperature_lists, \
#     windspeed_lists, pressure_lists, humidity_lists, cloud_lists = weather_data(city)
#     return temperature_line(time_list, temperature_lists), \
#            humidity_liquid(humidity_lists), \
#            windspeed_effectScatter(time_list, windspeed_lists), \
#            high_low_temperature_line(data_list, high_temperature, low_temperature), \
#            pressure_gauge(time_list, pressure_lists), \
#            cloud_scatter(time_list, cloud_lists), \
#            seven_day_table(seven_dayList)

if __name__ == '__main__':
    get_chart('衡陽市')

思路:圖表的繪制就沒什么可說的了,可自行查閱官方文檔:簡介 - pyecharts - A Python Echarts Plotting Library built with love.

這里務必使用pyecharts的組合圖表將多個圖組合在一起返回,不要像get_charts函數(shù)一樣返回多個圖表類?。?!

pyecharts+flask,python,flask,爬蟲,echarts?

組合圖表建議使用這種,當時也使用了Grid,但繪制的圖表,位置有問題不規(guī)范好看,自己不熟練的問題(教訓:多看看官方文檔,害我想了好久?。。?/p>

pyecharts+flask,python,flask,爬蟲,echarts?

?3.templates包前端代碼以及app.py文件的書寫

3.1.app.py文件的書寫
from flask import Flask, render_template, request, send_from_directory, render_template_string
from pyecharts.render import make_snapshot, snapshot

from WeatherXM.service.dataShow import get_chart

app = Flask(__name__, static_folder="static", template_folder='templates')


@app.route("/")
def index():
    return render_template("index.html")


@app.route("/getdata", methods=['GET'])
def get_weather_data():
    city = request.args.get('city')
    page = get_chart(city)

    # page.render('page.html')
    # print(a.dump_options_with_quotes())

    # return send_from_directory('../', 'page.html') # 成功
    
    # return render_template('page1.html', chart=page.render_embed()) # 失敗

    chart = page.render_embed()
    
    return render_template_string(chart)


if __name__ == "__main__":
    app.run()
3.2.index.html文件的書寫?
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Awesome-pyecharts</title>
<!--    <script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.min.js"></script>-->
<!--    <script type="text/javascript" src="https://assets.pyecharts.org/assets/echarts.min.js"></script>-->
    <!-- 引入 Pyecharts 以及 Liquid Chart 組件的依賴庫 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/pyecharts@1.9.0/dist/pyecharts.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts-liquidfill@2.1.0/echarts-liquidfill.min.js"></script>
    <link  rel="stylesheet">
    <link rel="stylesheet" href="../static/main.css" type="text/css">
</head>
<body>
<div class="title">
    <span>天氣查詢:</span>
    <input placeholder="請輸入城市" type="text" id="city">
    <button id="getdata">搜索</button>
</div>
<!--<div id="a" style="width:1000px; height:600px;"></div>-->
<div id="a"></div>
<!--    <div id="chartContainer">-->
<!--        <iframe src="{{ url_for('static', filename='page.html') }}" width="100%"  frameborder="0"></iframe>-->
<!--    </div>-->
<script>
    $("#getdata").click(function () {
            let city = $("#city").val()
            if (city === '') {
                alert('輸入錯誤,請重新輸入')
                return;
            }
            echarts.init(document.getElementById('a'), 'white', {renderer: 'canvas'})
            // let chart = echarts.init(document.getElementById('a'), 'white', {renderer: 'canvas'})
            $.ajax({
                type: "GET",
                url: "/getdata",
                // dataType: 'json/text',
                data: {'city': city},
                success: function (result) {
                    // chart.setOption(result)
                    $('#a').html(result);
                    // // 將獲取到的頁面插入到指定的容器中
                    // var chartContainer = document.getElementById('a');
                    // chartContainer.innerHTML = result;

                },
                error: function (result) {
                    alert('輸入的城市不存在,請重新輸入!')
                }
            })
        }
    )
</script>
</body>
</html>

思路:通過點擊搜索,發(fā)送數(shù)據(jù)給后端,后端返回html字符串,前端使用使用html解析

遇到的問題點:這里我使用的是使用?render_template_string函數(shù)來渲染簡單的模板或動態(tài)生成的 HTML 內(nèi)容,并返回給前端,也可以使用send_from_directory函數(shù)返回繪制好的Page.html文件

這里為什么不采用官網(wǎng)的a.dump_options_with_quotes()(本質(zhì)是將a這個圖類轉(zhuǎn)化為HTML)呢?

答:因為不能返回多個HTML,不然前端無法解析,也不能各自轉(zhuǎn)化為json數(shù)據(jù),前端接收不到

這里之前我的思路是將多個圖類返回,使用a.dump_options_with_quotes()直接返回列表給前端,或使用jsons數(shù)據(jù)返回,但前端就是接收不到,弄得我好煩,之后看了flask的文檔看到了這兩個方法!!有興趣的可以試試其他的!!

4.static(資源文件)

pyecharts+flask,python,flask,爬蟲,echarts?

?思路:這里一定要配置static_folder,template_folder,不然加載不出來的,不要問我為什么,嗚嗚嗚??!

cityinfo.xls文件地址:cityinfo.xls文件

pyecharts+flask,python,flask,爬蟲,echarts?

至此,項目就寫完了,可以準備啟動了

?四、項目啟動

點擊右上角的編輯配置,配置flask服務器:

pyecharts+flask,python,flask,爬蟲,echarts

pyecharts+flask,python,flask,爬蟲,echarts

?配置好點擊運行,點擊地址就行了

pyecharts+flask,python,flask,爬蟲,echarts

gitee地址:
python+pyecharts+flask+爬蟲實現(xiàn)實時天氣查詢可視化: 本項目使用python語言編寫,采用Flaskweb框架來實現(xiàn)前后端交互,利于開發(fā),維護,前端使用Html和jQuery處理事件,發(fā)送數(shù)據(jù)等,后端采用requests庫,BeautifulSoup庫實現(xiàn)爬取中國氣象局的數(shù)據(jù),清洗轉(zhuǎn)化成對應表格數(shù)據(jù)格式,再使用pyecharts繪制圖形,返回給前端頁面實現(xiàn)實時展示,注意運行本項目需要聯(lián)網(wǎng)?。?! (gitee.com)https://gitee.com/TheQuietCoder/WeatherXM

五、項目心得

整個項目說起來也簡單,但其實問題也挺多的,不斷遇到bug,不斷解決bug,有時候為了解決一個bug,網(wǎng)頁都翻爛了都找不到解決方法,這個過程是需要耐心的,當你真正解決了它,回過頭看也不過如此,我相信這些bug終將成為你成功的墊腳石,回首望去,輕舟已過萬重山??!

項目書寫,碼字不易,希望各位大佬們能留個贊??吧!?。?span toymoban-style="hidden">文章來源地址http://www.zghlxwxcb.cn/news/detail-772135.html

到了這里,關(guān)于python+pyecharts+flask+爬蟲實現(xiàn)實時天氣查詢可視化的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • 微信小程序之天氣查詢小案例

    微信小程序之天氣查詢小案例

    本次小項目是關(guān)于微信小程序-動態(tài)查詢天氣(墨跡天氣Api) 此次案例分為以下幾個準備方面: 一.準備方面: (1)如何發(fā)起請求?查看文檔:RequestTask | 微信開放文檔 (2)如何獲取定位信息?查看文檔:wx.getLocation(Object object) | 微信開放文檔 (3)如何控制頁面來實現(xiàn)數(shù)據(jù)實時渲染?查看文檔:

    2024年02月11日
    瀏覽(25)
  • html作業(yè)天氣查詢界面(html+css)

    html作業(yè)天氣查詢界面(html+css)

    目錄 一、作業(yè)要求 二、題目分析 三、最終演示 四、代碼 五、心得 利用百度主頁的天氣查詢程序?qū)崿F(xiàn)一個可以實時查詢武漢市天氣的靜態(tài)頁面 提示:獲取天氣數(shù)據(jù)的地址為(http://www.baidu.com/home/other/data/weatherInfo?city=武漢), (該網(wǎng)站返回一個json對象)界面要求如下圖。

    2024年02月11日
    瀏覽(25)
  • 微信小程序—天氣預報查詢

    微信小程序—天氣預報查詢

    前不久用安卓做了個天氣預報,麻煩的要死,故想體驗一下微信小程序開發(fā)(其實沒有可比性) 發(fā)現(xiàn)了一個免費的天氣接口 天氣接口api 地址:http://wthrcdn.etouch.cn/weather_mini?city=城市名稱 (1)index.wxml文件 (2)index.wxss文件 (3)index.js文件 主要是實現(xiàn)三個動作 一個是初始化加

    2024年02月12日
    瀏覽(41)
  • 微信小程序生成一個天氣查詢的小程序

    頁面結(jié)構(gòu):包括一個輸入框和一個查詢按鈕。 頁面邏輯:在用戶輸入城市名稱后,點擊查詢按鈕,跳轉(zhuǎn)到天氣詳情頁面,并將城市名稱作為參數(shù)傳遞。 index.js index.wxml index.wxss weather.js weather.wxml weather.wxss 首頁和天氣詳情頁。用戶可以在首頁輸入城市名稱后,點擊查詢按鈕跳轉(zhuǎn)

    2024年02月04日
    瀏覽(26)
  • 「教程」微信小程序獲取經(jīng)緯度查詢天氣預警信息

    「教程」微信小程序獲取經(jīng)緯度查詢天氣預警信息

    使用天氣預警API 可以幫助人們及時獲取和了解天氣預警信息,以便采取相應的措施來保護自身和財產(chǎn)。天氣預警通常是由氣象部門或相關(guān)機構(gòu)發(fā)布的,用于提醒公眾可能出現(xiàn)的極端天氣或自然災害,如暴雨、洪水、臺風、暴風雪、雷暴、高溫、低溫、霜凍等。 本文將詳細介

    2024年02月08日
    瀏覽(31)
  • 【Python】實現(xiàn)爬蟲(完整版),爬取天氣數(shù)據(jù)并進行可視化分析

    【Python】實現(xiàn)爬蟲(完整版),爬取天氣數(shù)據(jù)并進行可視化分析

    ??????大家好呀,你們的作業(yè)俠又轟轟轟的出現(xiàn)了,這次給大家?guī)淼氖莗ython爬蟲,實現(xiàn)的是爬取某城市的天氣信息并使用matplotlib進行圖形化分析?????? 要源碼可私聊我。 大家的關(guān)注就是我作業(yè)俠源源不斷的動力,大家喜歡的話,期待三連呀?????? 往期源碼

    2024年02月05日
    瀏覽(27)
  • Python項目開發(fā):Flask基于Python的天氣數(shù)據(jù)可視化平臺

    Python項目開發(fā):Flask基于Python的天氣數(shù)據(jù)可視化平臺

    目錄 步驟一:數(shù)據(jù)獲取 步驟二:設(shè)置Flask應用程序 步驟三:處理用戶輸入和數(shù)據(jù)可視化 步驟四:渲染HTML模板 總結(jié) 在這個數(shù)字化時代,數(shù)據(jù)可視化已經(jīng)成為我們理解和解釋信息的重要手段。在這個項目中,我們將使用Python語言來開發(fā)一個基于Flask框架的天氣數(shù)據(jù)可視化平臺

    2024年02月09日
    瀏覽(33)
  • python 爬蟲爬取天氣

    python 爬蟲爬取天氣

    爬蟲5步曲: 1.安裝requests and beacutifulsoup4庫 2.獲取爬蟲所需的header 和cookie 3.獲取網(wǎng)頁,解析網(wǎng)頁 4.分析得到的數(shù)據(jù)簡化地址 5.爬取內(nèi)容,清洗數(shù)據(jù) 1.安裝requestsbeautifulsoup4 ????????pip3 install requests ????????pip3 install beautifulsoup4 2.獲取爬蟲所需的header 和cookie 打開想爬取的

    2024年02月08日
    瀏覽(23)
  • 爬蟲:python如何獲得天氣數(shù)據(jù)

    爬蟲:python如何獲得天氣數(shù)據(jù)

    2.1?網(wǎng)站的內(nèi)容 主要是下方的天氣情況 2.2開始與網(wǎng)站獲得連接 當出現(xiàn)Response[200]時,此刻以與網(wǎng)站連接成功 2.3對網(wǎng)頁進行解析 ?采用‘utf-8’來對爬去的信息進行解碼,對網(wǎng)頁解析用到BeautifulSoup庫。 ????????當出現(xiàn)網(wǎng)站訪問成功,卻得不到數(shù)據(jù)時。 html.parser換成其他Bea

    2024年02月05日
    瀏覽(36)
  • 【python爬蟲】——歷史天氣信息爬取

    【python爬蟲】——歷史天氣信息爬取

    在2345天氣信息網(wǎng)2345天氣網(wǎng) 依據(jù) 地點 和 時間 對相關(guān)城市的歷史天氣信息進行爬取。 網(wǎng)頁使用get方式發(fā)送請求,所需參數(shù)包括areaInfo[areaId]、areaInfo[areaType]、date[year]、date[month],分別為城市id、城市類型,年、月。

    2024年02月07日
    瀏覽(26)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包