版权声明:数据版权归中央气象局所有,仅供学习交流之用。本文内容若有侵权,请联系我删除~
前言
调研了很天气平台,发现都需要注册,注册后通过key来uri访问, 虽然便捷简单,但是像高德这种还有刷新次数限制,并且通过平台获取到数据并不是很完整的,仅仅就是天气预测的基本信息,没有天气预报网页API那样丰富
需要获取的URL
1 获取相关接口
通过解析html页面后,发现有如下3个接口:
- 省份获取:
http://www.nmc.cn/rest/province
- 城市获取:
http://www.nmc.cn/rest/province/{省份代码}
- 城市天气预报获取:
http://www.nmc.cn/rest/weather?stationid={城市代码}
2 省份获取接口数据
接口:http://www.nmc.cn/rest/province
返回数据
[
{"code":"ABJ","name":"北京市","url":"/publish/forecast/ABJ.html"},
{"code":"ATJ","name":"天津市","url":"/publish/forecast/ATJ.html"},
{"code":"AHE","name":"河北省","url":"/publish/forecast/AHE.html"},
{"code":"ASC","name":"四川省","url":"/publish/forecast/ASC.html"},
...
...
{"code":"ATW","name":"台湾省","url":"/publish/forecast/ATW.html"}
]
注意:这里的code
键的值为城市获取的参数,如北京的参数为:ABJ
3 城市获取接口数据
接口:http://www.nmc.cn/rest/province/ABJ
返回数据
[
{
"code": "54511",
"province": "北京市",
"city": "北京",
"url": "/publish/forecast/ABJ/beijing.html"
},
{
"code": "54499",
"province": "北京市",
"city": "昌平",
"url": "/publish/forecast/ABJ/changping.html"
},
...
...
{
"code": "54406",
"province": "北京市",
"city": "延庆",
"url": "/publish/forecast/ABJ/yanqing.html"
}
]
4 城市天气预报获取接口数据
接口:http://www.nmc.cn/rest/weather?stationid=54511
返回数据
{
"msg": "success",
"code": 0,
"data": {
"real": {
"station": {
"code": "54511",
"province": "北京市",
"city": "北京",
"url": "/publish/forecast/ABJ/beijing.html"
},
"publish_time": "2024-02-27 16:15",
"weather": {
"temperature": 5.5,
"temperatureDiff": 1.1,
"airpressure": 9999,
"humidity": 37,
"rain": 0,
"rcomfort": 42,
"icomfort": -2,
"info": "多云",
"img": "1",
"feelst": 2.1
},
"wind": {
"direct": "西南风",
"degree": 261,
"power": "微风",
"speed": 2.7
},
"warn": {
"alert": "9999",
"pic": "9999",
"province": "9999",
"city": "9999",
"url": "9999",
"issuecontent": "9999",
"fmeans": "9999",
"signaltype": "9999",
"signallevel": "9999",
"pic2": "9999"
}
},
"predict": {
"station": {
"code": "54511",
"province": "北京市",
"city": "北京",
"url": "/publish/forecast/ABJ/beijing.html"
},
"publish_time": "2024-02-27 12:00",
"detail": [
{
"date": "2024-02-27",
"pt": "2024-02-27 12:00",
"day": {
"weather": {
"info": "多云",
"img": "1",
"temperature": "6"
},
"wind": {
"direct": "南风",
"power": "微风"
}
},
"night": {
"weather": {
"info": "多云",
"img": "1",
"temperature": "-3"
},
"wind": {
"direct": "北风",
"power": "微风"
}
}
},
...
...
{
"date": "2024-03-04",
"pt": "2024-02-27 12:00",
"day": {
"weather": {
"info": "阴",
"img": "2",
"temperature": "7"
},
"wind": {
"direct": "东北风",
"power": "微风"
}
},
"night": {
"weather": {
"info": "多云",
"img": "1",
"temperature": "-2"
},
"wind": {
"direct": "北风",
"power": "3~4级"
}
}
}
]
},
"air": {
"forecasttime": "2024-02-27 15:00",
"aqi": 81,
"aq": 2,
"text": "良",
"aqiCode": "99006;99008;99009;99010;99011;99013;99014;99015;99016;99017"
},
"tempchart": [
{
"time": "2024/02/20",
"max_temp": -1.3,
"min_temp": -5.6,
"day_img": "9999",
"day_text": "9999",
"night_img": "9999",
"night_text": "9999"
},
...
...
{
"time": "2024/03/04",
"max_temp": 7,
"min_temp": -2,
"day_img": "2",
"day_text": "阴",
"night_img": "1",
"night_text": "多云"
}
],
"passedchart": [
{
"rain1h": 0,
"rain24h": 9999,
"rain12h": 9999,
"rain6h": 9999,
"temperature": 5.5,
"tempDiff": "",
"humidity": 38,
"pressure": 1022,
"windDirection": 262,
"windSpeed": 3.3,
"time": "2024-02-27 16:00"
},
...
...
{
"rain1h": 0,
"rain24h": 9999,
"rain12h": 9999,
"rain6h": 9999,
"temperature": 3.9,
"tempDiff": "",
"humidity": 36,
"pressure": 1029,
"windDirection": 231,
"windSpeed": 3.3,
"time": "2024-02-26 17:00"
}
],
"climate": {
"time": "1981年-2010年",
"month": [
{
"month": 1,
"maxTemp": 1.8,
"minTemp": -7.3,
"precipitation": 2.8
},
....
....
{
"month": 11,
"maxTemp": 10.2,
"minTemp": 0.6,
"precipitation": 9.6
},
{
"month": 12,
"maxTemp": 3.5,
"minTemp": -5.1,
"precipitation": 2
}
]
},
"radar": {
"title": "华北",
"image": "/product/2024/02/27/RDCP/SEVP_AOC_RDCP_SLDAS3_ECREF_ANCN_L88_PI_20240227082400000.PNG?v=1709022833859",
"url": "/publish/radar/huabei.html"
}
}
}
注意:过期的数据值都为9999。
使用 Qt 代码提取数据
看公众号…