用ASP+XMLHTTP编写天气预报程序

13 篇文章 0 订阅
2 篇文章 0 订阅
本文介绍了一个使用ASP编写的天气预报脚本,该脚本通过HTTP请求获取指定城市的天气信息,并将数据解析后输出为易于展示的格式。文章详细展示了如何利用Microsoft.XMLHTTP对象从中国天气网获取绵阳市的天气预报数据。
摘要由CSDN通过智能技术生成
下面是小偷的内容:

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, ">", ">")
   fString = replace(fString, "<", "<")
   fString = Replace(fString, CHR(32), " ") '&nbsp;
   fString = Replace(fString, CHR(9), " ") '&nbsp;
   fString = Replace(fString, CHR(34), """)
   fString = Replace(fString, CHR(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
%>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值