首 页 网站运营 网络编程 网页制作 图象媒体 数据库 建站资源 网管专区 下载专区 最新资讯
IT学堂|红色黑客联盟
设为首页
加入收藏
联系站长
您所在的位置:首页>网络编程>ASP>文章内容
采用XMLHTTP编写一个天气预报的程序
来源: 作者: 发布时间:2007-04-12

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

下面是小偷的内容
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
%>




[推荐] [返回顶部] [打印本页] [关闭窗口]
热点文章
·ASP如何获取客户端真实IP地址
·ASP实现可显示和隐藏的树型菜单
·用ASP动态生成JS的表单验证代码
·ASP:用Asp编程实现QQ的在线情况查询
·ASP:用ASP打造一个小型的网页BBS系统
·ASP:用ASP编程实现网络内容快速查找
·ASP:利用ASP把图片上传到数据库
·ASP无法更新ACCESS数据库解决方法
·如何对ASP.NET进行性能优化
·入门:防范SQL注入攻击的新办法
相关文章
·Delphi编写组件封装asp代码的基本步骤
·菜鸟详听ASP中也能解压缩rar文件
·用ASP制作张扬个性的调查系统
·纯ASP代码之公历转农历实现(含属相)
·使用XMLHTTP制作域名查询系统
·用Asp+XmlHttp实现RssReader功能
·基于ASP的收发文管理系统的设计与实现
·纯ASP代码之公历转农历实现(含属相)--
·XmlHttp异步获取网站数据的例子
·实例讲解ASP实现抓取网上房产信息
文章检索
Google
相关文章
·Delphi编写组件封装asp
·菜鸟详听ASP中也能解压
·用ASP制作张扬个性的调
·纯ASP代码之公历转农历
·使用XMLHTTP制作域名查
·用Asp+XmlHttp实现RssRe
·基于ASP的收发文管理系
·纯ASP代码之公历转农历
·XmlHttp异步获取网站数
·实例讲解ASP实现抓取网
·解密ASP源代码
·asp提供在线文章翻译的
·用ASPJPEG组件制作图片
·如何使用PHP获取网络上
·各种存储过程使用指南