DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> XML學習教程 >> XML詳解 >> 采用XMLHTTP編寫一個天氣預報的程序
采用XMLHTTP編寫一個天氣預報的程序
編輯:XML詳解     

FileName TianQi.ASP
Write By Niaoked QQ408611119
www.knowsky.com
<%
if hour(now)=9 and minute(now)<30 then
getCategorIEs()
end if
Function getCategorIEs()
on error resume next
Dim oXMLHTTP ' As Object
Dim oCategorIEs ' As Object
Dim BodyText
Dim Pos,Pos1
Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")
'--- set the XMLHTTP call and issue send (no parm as category
'--- is included in URL
oXMLHTTP.open "GET","http://weather.china.com.cn/travel_gntq.PHP?cityid=56196&cityname=綿陽",False '這個地方換成你自己的地址
oXMLHTTP.send
'--- load the response into the CategorIEs data island
BodyText=oXMLHTTP.responsebody
BodyText=BytesToBstr(BodyText,"gb2312")
Pos=Instr(BodyText,"<body")
pos1=Instr(BodyText,"</body>")
BodyText=mid(BodyText,pos,pos1)
BodyText=split(BodyText,"<table")
Pos=Instr(BodyText(4),"<tr")
pos1=Instr(BodyText(4),"</tr>")
Body=mid(BodyText(4),pos,len(BodyText(4))-pos)
body=split(body,"</table>")
body1=split(replace(replace(replace(body(0),"<br>",""),"</td>",""),"</tr>",""),"天氣")
for i= 1 to ubound(body1)
body3=split(body1(i),"<td")
weather=weather & "document.write("""& i&"$" & "天氣" & HtmlEncode(trim(body3(0))) & """);" & vbcrlf
next
weather=replace(weather,"1$","<FONT color=#ffffff>【今天】</FONT>")
weather=replace(weather,"2$","<FONT color=#ffffff>【明天】</FONT>")
weather=replace(weather,"3$","<FONT color=#ffffff>【後天】</FONT>")
Set fs = CreateObject("Scripting.FileSystemObject")
 Set f = fs.CreateTextFile(request.ServerVariables("APPL_PHYSICAL_PATH")& "tq.JS", True)
 f.write("document.write('綿陽天氣預報:');" &vbcrlf & replace(weather,"<BR>",""))
 f.close
 Set f = nothing
 Set fs = nothing
response.write "綿陽天氣預報:"& weather
Set oXMLHTTP = Nothing
if err.number<>0 then
response.write "出錯了,錯誤描述:"&err.description & "<br>錯誤來源"& err.source
response.End()
end if
End Function
  
Function BytesToBstr(body,Cset)
    dim obJStream
    set obJStream = Server.CreateObject("adodb.stream")
    obJStream.Type = 1
    obJStream.Mode =3
    obJStream.Open
    obJStream.Write body
    obJStream.Position = 0
    obJStream.Type = 2
    obJStream.Charset = Cset
    BytesToBstr = obJStream.ReadText
    obJStream.Close
    set obJStream = nothing
End Function
Public Function HtmlEncode(fString)
 If Not IsNull(fString) Then
  fString = replace(fString, ">", "&gt;")
  fString = replace(fString, "<", "&lt;")
  fString = Replace(fString, CHR(32), " ") '&nbsp;
  fString = Replace(fString, CHR(9), " ")  '&nbsp;
  fString = Replace(fString, CHR(34), "&quot;")
  fString = Replace(fString, CHR(39), "&#39;") '單引號過濾
  fString = Replace(fString, CHR(13), "")
  fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
  fString = Replace(fString, CHR(10), "<BR> ")
  HtmlEncode = fString
 End If
End Function
%>


XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved