RSS Data Reading for Weather Forecasts (source code for free weather forecasts)

Source: Internet
Author: User

The URL for obtaining the 72-hour weather forecast is:

Http://weather.all2rss.com/

 

For example:

The weather forecast for Shenzhen is:

Http://weather.all2rss.com/weatherrss.asp? City =% C9 % ee % db % da(Note: The red part can be replaced with the appropriate city HTML code)

 

RSS data is:

<? XML version = "1.0" encoding = "gb2312"?> <RSS version = "2.0"> <channel> <title> 72-hour Weather Forecast in Shenzhen </title> <description> 72-hour Weather Forecast in Shenzhen </description> <copyright/> <language> en-CN </language> <lastbuilddate> 9:15:11 </lastbuilddate> <link> http://weather.all2rss.com/</link> <TTL> 30 </TTL> <item> <title> <! [CDATA [October 11-today: light rain 25 ℃ ~ 29 ℃ breeze is less than 3 levels; tomorrow: Cloudy 25 ℃ ~ 29 ℃ breeze is less than 3; The Day After Tomorrow: Cloudy 25 ℃ ~ 29 ℃ breeze less than 3 levels]> </title> <link> <! [CDATA [http://weather.all2rss.com/city.asp? Id = 219 & City = Shenzhen & date = 2010-10-11-]> </link> <description> <! [CDATA []> </description> <author> </author> <pubdate> Mon, 11 Oct 2010 09:15:11 + 0800 </pubdate> </item> </channel> </RSS>

 

Then extract the corresponding data using the relevant programming language.

 

For example, get the weather forecast (ASP) code within three days:

 

// 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, "today", "<B> <font color =" red ""> today </font> </B> ")
Result = Replace (result, "Tomorrow", "<B> tomorrow </B> ")
Result = Replace (result, "The Day After Tomorrow", "<B> The Day After Tomorrow </B> ")
Readrss = Result
End Function
Response. Write ("document. Write ('" & readrss ("http://weather.all2rss.com/weatherrss.asp? City= % B4 % F3 % Cd % AC")&"');")
%>

 

Call method:

Save the above Code as getweather. asp and put it in a suitable directory (for example,/weather). Then insert the following code in a proper location on other webpages.

<Script language = "JavaScript" src = "/weather/getweather. asp" charset = "gb2312"> </SCRIPT>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.