• 如何免费获得一个市全年的气象数据?降雨量气温湿度太阳辐射等等数据


        气象数据一直是一个价值较高的数据,它被广泛用于各个领域的研究当中。气象数据包括有气温、气压、相对湿度、降水、蒸发、风向风速、日照等多种指标,但是包含了这些全部指标的气象数据却较难获取,即使获取到了也不能随意分享。

            想要大规模爬取的话,需要自己写爬虫,我之前写过一个爬取深圳市数据的爬虫。对深圳市的天气数据爬取基本没有问题。

    1. import requests
    2. import demjson
    3. import re
    4. import calendar
    5. import csv
    6. headers = {
    7. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36\
    8. (KHML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
    9. }
    10. def get_url(date):
    11. url = 'https://www.timeanddate.com/scripts/cityajax.php?n=china/shenzhen&mode=historic'
    12. url += '&hd=' + date
    13. url += '&month=' + str(int(date[4:6]))
    14. url += '&year=' + date[:4] + '&json=1'
    15. return url
    16. # input: type(str) eg:'20170601'
    17. def crawl_single_day(date):
    18. response = requests.get(get_url(date), headers=headers)
    19. response_list = demjson.decode(response.text)
    20. for weather in response_list:
    21. w_time = re.compile(r'^\d+:\d+').search(weather['c'][0]['h']).group(0)
    22. w_temperature = re.compile(
    23. r'^-?\d+').search(weather['c'][2]['h']).group(0)
    24. w_weather = re.compile(
    25. r'^(.*?)\.').search(weather['c'][3]['h']).group(1)
    26. if weather['c'][4]['h'] == 'No wind':
    27. w_wind_speed = '0'
    28. else:
    29. w_wind_speed = re.compile(
    30. r'^\d+').search(weather['c'][4]['h']).group(0)
    31. w_wind_direction = re.compile(
    32. r'title=\"(.*?)\"').search(weather['c'][5]['h']).group(1)
    33. w_humidity = weather['c'][6]['h']
    34. w_barometer = re.compile(r'^\d+').search(weather['c'][7]['h']).group(0)
    35. w_visibility = weather['c'][8]['h']
    36. if w_visibility != 'N/A':
    37. w_visibility=re.compile(r'^\d+').search(w_visibility).group(0)
    38. yield [date, w_time, w_temperature, w_weather, w_wind_speed, w_wind_direction,
    39. w_humidity, w_barometer, w_visibility]
    40. # input: type(int) eg: year=2017, month=6
    41. def crawl_single_month(year, month):
    42. _, num_day = calendar.monthrange(year, month)
    43. month_str = str(year)
    44. if month < 10:
    45. month_str += '0' + str(month)
    46. else:
    47. month_str += str(month)
    48. day_list = list(range(1, num_day + 1))
    49. for day in day_list:
    50. if day < 10:
    51. for weather in crawl_single_day(month_str + '0' + str(day)):
    52. yield weather
    53. else:
    54. for weather in crawl_single_day(month_str + str(day)):
    55. yield weather
    56. if __name__ == "__main__":
    57. with open('weather0.csv', 'w', encoding='utf-8', newline='') as file:
    58. writer = csv.writer(file)
    59. writer.writerow('date time temperature weather wind_speed wind_direction humidity barometer visibility'.split())
    60. for month in range(7, 13):
    61. writer.writerows(crawl_single_month(2017, month))
    62. with open('weather1.csv', 'w', encoding='utf-8', newline='') as file:
    63. writer = csv.writer(file)
    64. writer.writerow('date time temperature weather wind_speed wind_direction humidity barometer visibility'.split())
    65. writer.writerows(crawl_single_day('20210401'))

    对 20210401的深圳天气数据爬取获得的 csv 文件如下图所示:

     

    当然啦,需求量比较大的话,可以通过地理遥感生态网平台获取气象数据。 

    地理遥感生态网平台发布的气象数据包括有气温、气压、相对湿度、降水、蒸发、风向风速、日照太阳辐射等等多种指标。

    1级目录

    文件名

    PRS

    SURF_CLI_CHN_MUL_DAY-PRS-10004-YYYYMM.TXT(本站气压)

    TEM

    SURF_CLI_CHN_MUL_DAY-TEM-12001-YYYYMM.TXT(气温)

    RHU

    SURF_CLI_CHN_MUL_DAY-RHU-13003-YYYYMM.TXT(相对湿度)

    PRE

    SURF_CLI_CHN_MUL_DAY-PRE-13011-YYYYMM.TXT(降水)

    EVP

    SURF_CLI_CHN_MUL_DAY-EVP-13240-YYYYMM.TXT(蒸发)

    WIN

    SURF_CLI_CHN_MUL_DAY-WIN-11002-YYYYMM.TXT(风向风速)

    SSD

    SURF_CLI_CHN_MUL_DAY-SSD-14032-YYYYMM.TXT(日照)

    GST

    SURF_CLI_CHN_MUL_DAY-GST-12030-0cm-YYYYMM.TXT(0cm地温)
     

       赶紧三连关注下, 数据获取途径如下:

  • 相关阅读:
    使用clip-path来画不同的形状,三角形,多边形,菱形,六边形等等
    信息学奥赛一本通:1181:整数奇偶排序
    在国内购买GPT服务前的一定要注意!!!
    CentOS7 安装MySQL 图文详细教程
    HTML+CSS鲜花静态网页设计
    ES中个别字段属性说明
    mysql导出表结构到excel
    Python 递归、排序和搜索
    基于桶的排序之基数排序以及排序方法总结
    获取个人免费版Ubuntu Pro
  • 原文地址:https://blog.csdn.net/m0_66892427/article/details/126125042