天气预报的RSS数据读取(免费天气预报源代码)
来源:互联网 发布:如何清除淘宝缓存 编辑:程序博客网 时间:2024/05/09 20:10
获取72小时天气预报的网址为:
http://weather.all2rss.com/
例如:
深圳的天气预报为:
http://weather.all2rss.com/weatherrss.asp?City=%C9%EE%DB%DA (注:红色部分可替换为合适的城市HTML编码)
RSS数据为:
<?xml version="1.0" encoding="gb2312" ?><rss version="2.0"><channel><title>深圳 72小时天气预报</title><description>深圳72小时天气预报 </description><copyright/><language>zh-cn</language><lastBuildDate>2010-10-11 9:15:11</lastBuildDate><link>http://weather.all2rss.com/</link><ttl>30</ttl><item><title><![CDATA[10月11日9时 - 今天:小雨 25℃~29℃ 微风 小于3 级; 明天:多云 25℃~29℃ 微风 小于3 级; 后天:多云 25℃~29℃ 微风 小于3 级]]></title><link><![CDATA[http://weather.all2rss.com/city.asp?id=219&city=深圳&date=2010-10-11-9:15]]></link><description><![CDATA[ ]]></description><author></author><pubDate>Mon, 11 Oct 2010 09:15:11 +0800</pubDate></item></channel></rss>
然后使用相关编程语言提取相应数据即可。
例如:获取三天内的天气预报(ASP)代码:
// getWeather.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
dim ml
ml = ml & "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"" />"
ml = ml & "<meta http-equiv=""X-UA-Compatible"" content=""IE=7"" />"
'Response.Write("document.write('" & ml & "');")
Function ReadRSS(xmlseed)
dim xmlDoc
dim http
Set http=Server.CreateObject("Microsoft.XMLHTTP")
http.Open "GET",xmlseed,False
http.send
Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.Async=False
xmlDoc.ValidateOnParse=False
xmlDoc.Load(http.ResponseXML)
dim result
if xmlDoc.ReadyState>2 Then
Set lastBuildDate=xmlDoc.getElementsByTagName("lastBuildDate")
dim channel_link
Set channelLink=xmlDoc.selectSingleNode("//channel/link")
channel_link = channelLink.Text
dim lastDate
lastDate = lastBuildDate.Item(0).Text
Set item=xmlDoc.getElementsByTagName("item")
if item.Length>0 then
For i=0 To (item.Length-1)
Set title=item.Item(i).getElementsByTagName("title")
Set link=item.Item(i).getElementsByTagName("link")
result= result & title.Item(0).Text
Next
end if
end if
Set xmlDoc=nothing
result = Replace(Split(result," - ")(1)," ","")
result = Replace(result,"今天","<b><font color=""red"">今天</font></b>")
result = Replace(result,"明天","<b>明天</b>")
result = Replace(result,"后天","<b>后天</b>")
ReadRSS = result
End Function
Response.Write("document.write('" & ReadRSS("http://weather.all2rss.com/weatherrss.asp?City=%B4%F3%CD%AC") & "');")
%>
调用方式:
将上述代码保存为getweather.asp,放在合适的目录下(如:/weather),之后在其他网页的合适的位置插入以下代码即可。
<script language="JavaScript" src="/weather/getweather.asp" charset="gb2312"></script>
- 天气预报的RSS数据读取(免费天气预报源代码)
- 读取RSS源的天气预报Web Server实现
- flask天气预报json数据的读取
- 天气预报的源代码
- 免费天气预报
- 免费天气预报
- 天气预报源代码
- 免费的天气预报webservice接口
- 免费的天气预报webservice接口
- 免费的天气预报webservice接口
- 免费的天气预报webservice接口
- 免费的天气预报webservice接口
- 免费的天气预报webservice接口
- 免费的天气预报webservice接口
- 免费的天气预报webservice接口
- 免费的天气预报webservice接口
- 天气预报的免费接口api
- 免费获取欧洲ECMWF两年的天气预报数据:
- 第一个mpi程序in linux
- C++如何在vim使用cscope
- find grep组合使用查找文件
- 你可能不知道的10个JavaScript小技巧
- 飞思卡尔测速仪器
- 天气预报的RSS数据读取(免费天气预报源代码)
- AUC(Area Under roc Curve )计算及其与ROC的关系
- 设置窗口的背景图片
- 正则表达式
- lag分析函数技巧
- 领悟 JavaScript 中的面向对象
- 我的四年本科(软件学院)
- 难道真是人品不好??~~~
- JavaScript中switch...case语句与if...else性能比较