中国国家气象局提供了获取所在城市天气预报信息接口。通过这个接口,我们就可以获取天气信息了。
关于获取天气预报的实例参考android学习手册,里面有源码。android学习手册包含9个章节,108个例子,源码文档随便看,例子都是可交互,可运行,源码采用android studio目录结构,高亮显示代码,文档都采用文档结构图显示,可以快速定位。360手机助手中下载,图标上有贝壳
中国国家气象局天气预报接口总共提供了三个:
>
>
>
注:上面接口201434日已不再更新。换成这个:>
最详细的信息来自第三个接口。上面url中的101010100是城市代码,这里是北京的城市代码。只需要改变城市代码,就可以得到所在城市的天气信息。笔者在福州,所以选择的城市代码是福州101230101。
在浏览器上输入url:>
{"weatherinfo":{"city":"福州","city_en":"fuzhou","date_y":"2012年5月14日","date":"","week":"星期一","fchh":"08","cityid":"101230101","temp1":"29℃~23℃","temp2":"26℃~20℃","temp3":"24℃~20℃","temp4":"25℃~20℃","temp5":"24℃~21℃","temp6":"25℃~22℃","tempF1":"842℉~734℉","tempF2":"788℉~68℉","tempF3":"752℉~68℉","tempF4":"77℉~68℉","tempF5":"752℉~698℉","tempF6":"77℉~716℉","weather1":"阵雨转中雨","weather2":"中雨转小雨","weather3":"小雨","weather4":"小雨","weather5":"小雨转阵雨","weather6":"阵雨转小雨","img1":"3","img2":"8","img3":"8","img4":"7","img5":"7","img6":"99","img7":"7","img8":"99","img9":"7","img10":"3","img11":"3","img12":"7","img_single":"3","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":"阵雨","wind1":"微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风","fx1":"微风","fx2":"微风","fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级","index":"热","index_d":"天气较热,建议着短裙、短裤、短套装、T恤等夏季服装。年老体弱者宜着长袖衬衫和单裤。","index48":"暖","index48_d":"较凉爽,建议着长袖衬衫加单裤等春秋过渡装。年老体弱者宜着针织长袖衬衫、马甲和长裤。","index_uv":"弱","index48_uv":"最弱","index_xc":"不宜","index_tr":"适宜","index_co":"较不舒适","st1":"27","st2":"21","st3":"24","st4":"18","st5":"22","st6":"18","index_cl":"较不宜","index_ls":"不太适宜","index_ag":"不易发"}}
我们可以解析json数据去得到自己想用的天气信息。
天气信息解释:
[html] view plain copy print
{
"weatherinfo":{
<!-- 基本信息 -->
"city":"福州",
"city_en":"fuzhou",
"date_y":"2012年5月14日",
"date":"",
"week":"星期一",
"fchh":"08",
"cityid":"101230101",
<!-- 从今天开始到第六天的每天的天气情况,这里的温度是摄氏温度 -->
"temp1":"29℃~23℃","temp2":"26℃~20℃","temp3":"24℃~20℃","temp4":"25℃~20℃","temp5":"24℃~21℃","temp6":"25℃~22℃",
<!-- 从今天开始到第六天的每天的天气情况,这里的温度是华氏温度 -->
"tempF1":"842℉~734℉","tempF2":"788℉~68℉","tempF3":"752℉~68℉","tempF4":"77℉~68℉","tempF5":"752℉~698℉","tempF6":"77℉~716℉",
<!-- 天气描述 -->
"weather1":"阵雨转中雨","weather2":"中雨转小雨","weather3":"小雨","weather4":"小雨","weather5":"小雨转阵雨","weather6":"阵雨转小雨",
<!-- 天气描述序号 -->
"img1":"3","img2":"8","img3":"8","img4":"7","img5":"7","img6":"99","img7":"7","img8":"99","img9":"7","img10":"3","img11":"3","img12":"7","img_single":"3",
<!-- 名称 -->
"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":"阵雨",
<!-- 风速描述 -->
"wind1":"微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风","fx1":"微风","fx2":"微风",
<!-- 风速级别描述 -->
"fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级",
<!-- 今天穿衣指数 -->
"index":"热",
"index_d":"天气较热,建议着短裙、短裤、短套装、T恤等夏季服装。年老体弱者宜着长袖衬衫和单裤。",
<!-- 48小时穿衣指数 -->
"index48":"暖","index48_d":"较凉爽,建议着长袖衬衫加单裤等春秋过渡装。年老体弱者宜着针织长袖衬衫、马甲和长裤。",
<!-- 紫外线及48小时紫外线 -->
"index_uv":"弱","index48_uv":"最弱",
<!-- 洗车 -->
"index_xc":"不宜",
<!-- 旅游 -->
"index_tr":"适宜",、
<!-- 舒适指数 -->
"index_co":"较不舒适",
"st1":"27","st2":"21","st3":"24","st4":"18","st5":"22","st6":"18",
<!-- 晨练 -->
"index_cl":"较不宜",
<!-- 晾晒 -->
"index_ls":"不太适宜",
<!-- 过敏 -->
"index_ag":"不易发"
}
}
{
"weatherinfo":{
<!-- 基本信息 -->
"city":"福州",
"city_en":"fuzhou",
"date_y":"2012年5月14日",
"date":"",
"week":"星期一",
"fchh":"08",
"cityid":"101230101",
<!-- 从今天开始到第六天的每天的天气情况,这里的温度是摄氏温度 -->
"temp1":"29℃~23℃","temp2":"26℃~20℃","temp3":"24℃~20℃","temp4":"25℃~20℃","temp5":"24℃~21℃","temp6":"25℃~22℃",
<!-- 从今天开始到第六天的每天的天气情况,这里的温度是华氏温度 -->
"tempF1":"842℉~734℉","tempF2":"788℉~68℉","tempF3":"752℉~68℉","tempF4":"77℉~68℉","tempF5":"752℉~698℉","tempF6":"77℉~716℉",
<!-- 天气描述 -->
"weather1":"阵雨转中雨","weather2":"中雨转小雨","weather3":"小雨","weather4":"小雨","weather5":"小雨转阵雨","weather6":"阵雨转小雨",
<!-- 天气描述序号 -->
"img1":"3","img2":"8","img3":"8","img4":"7","img5":"7","img6":"99","img7":"7","img8":"99","img9":"7","img10":"3","img11":"3","img12":"7","img_single":"3",
<!-- 名称 -->
"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":"阵雨",
<!-- 风速描述 -->
"wind1":"微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风","fx1":"微风","fx2":"微风",
<!-- 风速级别描述 -->
"fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级",
<!-- 今天穿衣指数 -->
"index":"热",
"index_d":"天气较热,建议着短裙、短裤、短套装、T恤等夏季服装。年老体弱者宜着长袖衬衫和单裤。",
<!-- 48小时穿衣指数 -->
"index48":"暖","index48_d":"较凉爽,建议着长袖衬衫加单裤等春秋过渡装。年老体弱者宜着针织长袖衬衫、马甲和长裤。",
<!-- 紫外线及48小时紫外线 -->
"index_uv":"弱","index48_uv":"最弱",
<!-- 洗车 -->
"index_xc":"不宜",
<!-- 旅游 -->
"index_tr":"适宜",、
<!-- 舒适指数 -->
"index_co":"较不舒适",
"st1":"27","st2":"21","st3":"24","st4":"18","st5":"22","st6":"18",
<!-- 晨练 -->
"index_cl":"较不宜",
<!-- 晾晒 -->
"index_ls":"不太适宜",
<!-- 过敏 -->
"index_ag":"不易发"
}
}
这个和用不用python没啥关系,是数据来源的问题。调用淘宝API,使用 api相关接口获得你想要的内容,我 记得api中有相关的接口,你可以看一下接口的说明。用python做爬虫来进行页面数据的获取。希望能帮到你。
由于大多浏览器默认禁止javascript跨域访问,你先载入信息到你的php脚本,然后用ajax跟你的php交互,有点蛮烦不过也是一种方法。
indexphp文件代码
<php
$url=">
百度API Key申请地址:>
创建应用 如图:
提交后得到API Key ,运行结果如下:
扩展资料:
API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码,或理解内部工作机制的细节。
API函数包含在Windows系统目录下的动态连接库文件中。Windows API是一套用来控制Windows的各个部件的外观和行为的预先定义的Windows函数。
参考资料:
# 获取温度、湿度、风力等
WEATHER_URL_A = ">
网络爬虫我不懂,你要获取天气网上面的数据,可以根据它提供的wsdl,用webservice去获取,
还有ajax请求,过去,如果成功后,返回的是json数据的话,取决于服务端,如果服务端没有json格式的数据让你返回的话,你应该是拿不到json数据的吧
以上就是关于android端免费获取天气信息的服务器接口有么全部的内容,包括:android端免费获取天气信息的服务器接口有么、如何使用python利用api获取天气预报、中国天气网的json格式天气信息,怎么通过网页显示出来html或者php都行等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)