一 天气预报
国内的天气预报数据,主要是国家气象局和国外两个来源(指数据来源)。
国外方面主要是雅虎(XML格式,谷歌已经停掉了自家的天气API);
国内数据由国家气象局提供( *** ON格式)。
在知乎看到过一篇专业人士评论,雅虎可以提供全球范围的且非常精细的天气数据(小时级更新),但主要是通过计算机自动生成。而国家气象局则是各地经验丰富的专家人士结合计算机综合分析得出,在准确性上更胜一筹。我就这样信了!
国家气象局接口资源及用法
气象局的天气预报主页:移动版普通版 ,仔细挖掘这两个地址可以发现很多好东西哦。
特点:接口多,来自weather.com.cn和mobile.weather.com.cn都有,次数不限制,服务稳定,功能全面,优先推荐。
百度API Key申请地址:
创建应用 如图:
提交后得到API Key ,运行结果如下:
扩展资料:
API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码,或理解内部工作机制的细节。
API函数包含在Windows系统目录下的动态连接库文件中。Windows API是一套用来控制Windows的各个部件的外观和行为的预先定义的Windows函数。
参考资料:百度百科-api接口
使用搜索引擎可以得到很多的天气预报接口,这里以某个api为例
参数为city=城市名称
尝试获取南昌的天气预报
南昌
得到下面xml数据
?xml version="1.0" encoding="utf-8"?
resp
city南昌/city
updatetime16:55/updatetime
wendu5/wendu
fengli3级/fengli
shidu90%/shidu
fengxiang北风/fengxiang
sunrise_106:54/sunrise_1
sunset_117:19/sunset_1
sunrise_2/
sunset_2/
environment
aqi26/aqi
pm2513/pm25
suggest各类人群可自由活动/suggest
quality优/quality
MajorPollutants/
o344/o3
co1/co
pm1014/pm10
so24/so2
no227/no2
time16:00:00/time
/environment
yesterday
date_14日星期五/date_1
high_1高温 11℃/high_1
low_1低温 7℃/low_1
day_1
type_1阴/type_1
fx_1无持续风向/fx_1
fl_1微风/fl_1
/day_1
night_1
type_1小到中雨/type_1
fx_1北风/fx_1
fl_13-4级/fl_1
/night_1
/yesterday
forecast
weather
date5日星期六/date
high高温 7℃/high
low低温 5℃/low
day
type中到大雨/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type小到中雨/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
weather
date6日星期天/date
high高温 10℃/high
low低温 5℃/low
day
type阴/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type多云/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
weather
date7日星期一/date
high高温 13℃/high
low低温 6℃/low
day
type多云/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type晴/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
weather
date8日星期二/date
high高温 13℃/high
low低温 7℃/low
day
type晴/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type多云/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
weather
date9日星期三/date
high高温 13℃/high
low低温 10℃/low
day
type小雨/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type小雨/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
/forecast
zhishus
zhishu
name晨练指数/name
value不宜/value
detail有较强降水,请避免户外晨练,建议在室内做适当锻炼,保持身体健康。/detail
/zhishu
zhishu
name舒适度/name
value较舒适/value
detail白天有雨,人们会感到有些凉意,但大部分人完全可以接受。/detail
/zhishu
zhishu
name穿衣指数/name
value较冷/value
detail建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。/detail
/zhishu
zhishu
name感冒指数/name
value极易发/value
detail将有一次强降温过程,天气寒冷,且空气湿度较大,极易发生感冒,请特别注意增加衣服保暖防寒。/detail
/zhishu
zhishu
name晾晒指数/name
value不宜/value
detail有较强降水,不适宜晾晒。若需要晾晒,请在室内准备出充足的空间。/detail
/zhishu
zhishu
name旅游指数/name
value较不宜/value
detail天气稍凉,有微风,同时有有较强降水,会给出行产生很多麻烦,建议好还是多选择在室内活动!。/detail
/zhishu
zhishu
name紫外线强度/name
value最弱/value
detail属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。/detail
/zhishu
zhishu
name洗车指数/name
value不宜/value
detail不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。/detail
/zhishu
zhishu
name运动指数/name
value较不宜/value
detail有较强降水,建议您选择在室内进行健身休闲运动。/detail
/zhishu
zhishu
name约会指数/name
value不适宜/value
detail较强降水天气会给室外约会增添许多麻烦,尽量不要外出约会,更好在室内促膝谈心。/detail
/zhishu
zhishu
name雨伞指数/name
value带伞/value
detail有较强降水,您在外出的时候一定要带雨伞,以免被雨水淋湿。/detail
/zhishu
/zhishus
/resp
得到数据后使用XML解析数据即可,更好是建立一个实体类来存储数据
下面是使用DOM方式解析部分数据代码
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
//is是 *** 连接得到的输入流
Document doc = builder.parse(is);
if(doc==null) throw new Exception();
Element element = doc.getDocumentElement();
NodeList childList = element.getChildNodes();
for(int i=0; ichildList.getLength(); i++){
Element e = (Element) childList.item(i);
String tag = e.getTagName();
String text = e.getTextContent();
if("city".equals(tag)){
//城市
}else if("updatetime".equals(tag)){
//更新时间
}else if("wendu".equals(tag)){
//即时温度
}else if("fengli".equals(tag)){
//风力
}else if("shidu".equals(tag)){
//湿度
}else if("fengxiang".equals(tag)){
//风向
}
}
找一个免费的天气预报API,它会以json格式返回数据,然后你自己取所需的数据就可以了
因微信公共号提供城市天气预报服务,发现网山天气预报接口和环境数据接口方面资料比较乱,而且有不少内容已经失效,下面内容由过程日志整理形成,希望可用得上。
一 天气预报
国内的天气预报数据,主要是国家气象局和国外两个来源(指数据来源)。
国外方面主要是雅虎(XML格式,谷歌已经停掉了自家的天气API);
国内数据由国家气象局提供( *** ON格式)。
在知乎看到过一篇专业人士评论,雅虎可以提供全球范围的且非常精细的天气数据(小时级更新),但主要是通过计算机自动生成。而国家气象局则是各地经验丰富的专家人士结合计算机综合分析得出,在准确性上更胜一筹。我就这样信了!
国家气象局接口资源及用法
气象局的天气预报主页:移动版普通版 ,仔细挖掘这两个地址可以发现很多好东西哦。
特点:接口多,来自weather.com.cn和mobile.weather.com.cn都有,次数不限制,服务稳定,功能全面,优先推荐。
1. 实时天气接口
有多个接口,好像差别不大:
实时天气1:
实时天气2:
实时天气3(带时间戳):
2. 一周天气预报接口
7天预报数据 URL:
该接口来源气象局移动版网站,目测数据最为精确,详细接口格式如下:
{"c":{"c1":"101010100","c2":"beijing","c3":"北京","c4":"beijing","c5":"北京","c6":"beijing","c7":"北京","c8":"china","c9":"中国","c10":"1","c11":"010","c12":"100000","c13":"116.391","c14":"39.904","c15":"33","c16":"AZ9010","c17":"+8"},
"f":{"f1":
[
{"fa":"01","fb":"03","fc":"10","fd":"5","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:21|17:40"},
{"fa":"07","fb":"07","fc":"19","fd":"12","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:22|17:38"},
{"fa":"02","fb":"00","fc":"15","fd":"5","fe":"8","ff":"8","fg":"3","fh":"1","fi":"06:23|17:37"},
{"fa":"00","fb":"00","fc":"16","fd":"4","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:24|17:35"},
{"fa":"00","fb":"00","fc":"18","fd":"7","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:25|17:34"},
{"fa":"00","fb":"01","fc":"18","fd":"8","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:26|17:32"},
{"fa":"01","fb":"01","fc":"16","fd":"6","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:27|17:31"}],
"f0":"201310121100"}}
详细接口分析如下:
//格式说明
var format={fa:图片1,fb:图片2,fc:温度1,fd:温度2,fe:风向1,ff:风向2,fg:风力1,fh:风力2,fi:日出日落};
//定义天气类型
var weatherArr={"00":"晴","01":"多云","02":"阴","03":"阵雨","04":"雷阵雨","05":"雷阵雨伴有冰雹","06":"雨夹雪","07":"小雨","08":"中雨","09":"大雨","10":"暴雨","11":"大暴雨","12":"特大暴雨","13":"阵雪","14":"小雪","15":"中雪","16":"大雪","17":"暴雪","18":"雾","19":"冻雨","20":"沙尘暴","21":"小到中雨","22":"中到大雨","23":"大到暴雨","24":"暴雨到大暴雨","25":"大暴雨到特大暴雨","26":"小到中雪","27":"中到大雪","28":"大到暴雪","29":"浮尘","30":"扬沙","31":"强沙尘暴","53":"霾","99":""};
//定义风向数组
var fxArr={"0":"无持续风向","1":"东北风","2":"东风","3":"东南风","4":"南风","5":"西南风","6":"西风","7":"西北风","8":"北风","9":"旋转风"};
//定义风力数组
var flArr={"0":"微风","1":"3-4级","2":"4-5级","3":"5-6级","4":"6-7级","5":"7-8级","6":"8-9级","7":"9-10级","8":"10-11级","9":"11-12级"};
6天预报数据 URL:
该接口来源 *** ,应该是一个流传比较久的接口,大发现准确性和稳定性可能不稳定。接口分析如下:
{"weatherinfo":{
#基本信息
"city":"北京","city_en":"beijing","date_y":"2013年9月24日","date":"","week":"星期二","fchh":"11","cityid":"101010100",
#6天温度范围
"temp1":"22℃~11℃","temp2":"25℃~11℃","temp3":"26℃~13℃","temp4":"25℃~15℃","temp5":"25℃~16℃","temp6":"24℃~16℃",
#6天温度范围(华氏)
"tempF1":"71.6℉~51.8℉","tempF2":"77℉~51.8℉","tempF3":"78.8℉~55.4℉","tempF4":"77℉~59℉","tempF5":"77℉~60.8℉","tempF6":"75.2℉~60.8℉",
#6天天气
"weather1":"多云转晴","weather2":"晴","weather3":"晴","weather4":"晴转多云","weather5":"阴转阵雨","weather6":"多云",
#6天天气图示(每天2张)
"img1":"1","img2":"0","img3":"0","img4":"99","img5":"0","img6":"99","img7":"0","img8":"1","img9":"2","img10":"3","img11":"1","img12":"99",
"img_single":"1",
#6天天气图示文字(每天2)
"img_title1":"多","img_title2":"晴","img_title3":"晴","img_title4":"晴","img_title5":"晴","img_title6":"晴","img_title7":"晴","img_title8":"多云","img_title9":"阴","img_title10":"阵雨","img_title11":"多云","img_title12":"多云",
"img_title_single":"多云",
#6天风
"wind1":"北风3-4级转微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风",
"fx1":"北风","fx2":"微风",
#6天风力情况
"fl1":"3-4级转小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级",
#24小时内
"index":"较冷","index_d":"建议着大衣、呢外套加毛衣、卫衣等服装。体弱者宜着厚外套、厚毛衣。因昼夜温差较大,注意增减衣服。",
#48小时内
"index48":"较舒适","index48_d":"建议着薄外套或牛仔衫裤等服装。年老体弱者宜着夹克衫、薄毛衣等。昼夜温差较大,注意适当增减衣服。",
#紫外 洗车 旅游 舒适指数 晨练 晾晒 过敏
"index_uv":"弱",
"index48_uv":"强",
"index_xc":"适宜",
"index_tr":"适宜",
"index_co":"舒",
"st1":"21","st2":"12","st3":"24","st4":"12","st5":"25","st6":"14", #不明
"index_cl":"较适宜",
"index_ls":"适宜",
"index_ag":"极易发"
}}
对于IT管理员和网络安全团队来说,勒索软件攻击是一场与时间赛跑的关键比赛,以检测和控制损害,同时抢救公司的数据资产的剩余部分。但是,当这种事件发生时,有多少反应时间呢?似乎不是很多。正如对10个候选勒索软件的测试所揭示的那样,一种名叫LockBit的勒索软件效率惊人,在四分钟内就加密了一台Windo...
BHI是一种影响大多数英特尔和Arm CPU的新型投机执行漏洞,它攻击分支全局历史而不是分支目标预测。不幸的是,这些公司以前对Spectre V2的缓解措施也无法保护BHI的威胁,尽管AMD处理器大多是免疫的。消息传出后,供应商应该很快就会发布安全补丁,而最新得Linux内核已经打了补丁。...
微软最近对Windows Defender的排除权限进行了更新,没有管理员权限就无法查看排除的文件夹和文件。这是一个重要的变化,因为威胁者往往会利用这一信息在这种被排除的目录中提供恶意软件的载荷,以绕过防御者的扫描。 然而,这可能无法阻止ZeroFox最近发现的一个名为Kraken的新僵尸网络。这...
Google和IBM在参加白宫关于开源安全问题的会议后,敦促科技组织联合起来,确定关键的开源项目。这次会议由白宫网络安全领导人Anne Neuberger领导,与会者包括Apache、Google、苹果、亚马逊、IBM、微软、Meta、Linux和Oracle等组织的官员,以及国防部和网络安全与基础...
近日,欧洲刑警组织发布了其首份深度伪造研究报告–《面对现实?执法和深度伪造的挑战》(Facing reality? Law enforcement and the challenge of deepfakes),这是欧洲刑警组织创新实验室就新兴技术的风险、威胁和机遇等方面技术发展研究形成的报告。该报...
时间已正式迈入 2022 年,分析公司 Chainalysis 表示在过去一年中与加密货币有关的犯罪达到了历史最高水平,非法地址获得了惊人的 140 亿美元。收到的绝大部分资金是通过诈骗、盗窃和暗网市场获得的,而另一个不断增长的被盗资金来源则是赎金。 非法资金从 2020 年的 78 亿美...