采用XMLHTTP编写一个天气预报的程序

作者:Niaoked 来源:knowsky 时间:2007-10-15 12:35:00 

  本人就职于一个本地门户网站,每天网站上的天气都得更新。久而久之感到相当麻烦,于是写了一个定时的新闻小偷,帖出来大家参考一下系统要求: 支持FSO, 服务器UDP TCP/IP    没有屏蔽

下面是小偷的内容

FileName TianQi.asp
Write By Niaoked QQ408611119
<%
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,HttpRequest,天气
0
投稿

猜你喜欢

  • Python中的默认参数实例分析

    2023-02-20 20:19:38
  • Vuejs学习笔记之使用指令v-model完成表单的数据双向绑定

    2023-07-02 16:28:13
  • JAVA正则表达式及字符串的替换与分解相关知识总结

    2023-02-01 20:59:53
  • SecureCRTSecure7.0查看连接密码的步骤

    2021-01-28 07:34:14
  • Google投放广告的js的分析

    2008-07-15 11:34:00
  • 用python实现的去除win下文本文件头部BOM的代码

    2021-04-01 08:00:19
  • goland -sync/atomic原子操作小结

    2024-04-26 17:20:08
  • 如何修复使用 Python ORM 工具 SQLAlchemy 时的常见陷阱

    2022-07-03 20:51:47
  • 实例解析Python设计模式编程之桥接模式的运用

    2021-06-03 18:48:04
  • php实现的单一入口应用程序实例分析

    2023-11-22 08:00:26
  • SSB(SQLservice Service Broker) 入门实例介绍

    2024-01-27 14:19:00
  • 手把手教你Python抓取数据并可视化

    2022-01-08 02:11:55
  • CentOS Linux更改MySQL数据库目录位置具体操作

    2024-01-23 18:13:49
  • Keras设置以及获取权重的实现

    2021-11-22 10:04:09
  • Python实现设置windows桌面壁纸代码分享

    2022-03-23 03:52:46
  • Python实现字符串匹配的KMP算法

    2021-02-10 05:03:45
  • Python根据成绩分析系统浅析

    2023-08-02 20:25:07
  • 微信小程序实现富文本图片宽度自适应的方法

    2023-10-17 12:44:25
  • mysql中自增auto_increment功能的相关设置及问题

    2024-01-16 09:34:13
  • java数据库操作类演示实例分享(java连接数据库)

    2024-01-28 03:30:20
  • asp之家 网络编程 m.aspxhome.com