采用XMLHTTP编写一个天气预报的程序
作者:Niaoked 来源:knowsky 发布时间:2007-10-15 12:35:00
标签:xml,HttpRequest,天气
本人就职于一个本地门户网站,每天网站上的天气都得更新。久而久之感到相当麻烦,于是写了一个定时的新闻小偷,帖出来大家参考一下系统要求: 支持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, ">", ">")
fString = replace(fString, "<", "<")
fString = Replace(fString, CHR(32), " ") ’
fString = Replace(fString, CHR(9), " ") ’
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
%>
0
投稿
猜你喜欢
- 想要一个这玩意,可是找了网上许多着色器,要么是兼容性成问题,要么是匹配不精确,比如说:1、注释里包含字符串、关键词,类似于:/* xxxx&
- 这几天看了篇叫"Penetration: from application down to OS (Oracle)"的文
- 五一在家写的,和大家分享,支持所有浏览器,添加了左侧菜单点击变色效果<!DOCTYPE html PUBLIC "-//W3
- 一位资深的设计师曾经向我抱怨,说老板不仅让他做“设计”工作,还让他做“制作”工作,真是很烦。言下之意,“制作”还要一个资深设计师亲自上阵,未
- 'subject 信息标题 'company 发布信息的公司名称 'cont
- 我们可以用动态产生变量的方法,从表格里捕捉数据,动态地创造“剥离”变量引号并且“清理”它,见下列代码,我们只需键入变量名称,选择 query
- 我们都一定对比过编程的轻松与简单性。虽然我们都确认php和perl是最容易学习和编程的语言,但我仍旧想知道,如果用php、asp、jsp以及
- MySQL低调宣布它将不再把MySQL企业版服务器作为一个tar包发布,而这距离这个公司宣布将MySQL分为免费版和付费版的时间还不到一年。
- 代码如下:<% dim objconn,connstr Set objconn =&
- 我们在编写 Javascript 时,Debug 是很痛苦的过程,而且有些语法问题虽使用 Firebug 能很快定位,但毕竟影响效率。这里有
- 我们知道,任何数据库系统都无法避免崩溃的状况,即使你使用了Clustered,双机热备……仍然无
- monfs :我想知道javascript是否可以实现这样的功能来改变本地的IP地址,例如我本地设置的IP地址是192.168.0.1,我想
- 1.触发器概述触发器是SQL Server数据库应用中一个重要工具,是一种特殊类型的存储过程,应用非常广泛。一般存储过程主要通过存储过程名而
- http://swik.net/Ajax/Ajax+Mistakes在某网站瞎逛时,发现这个链接,进去逛了逛,觉得很有意思,大家也可以去看看
- 有一次去超市换货,本能的找到服务中心,服务中心说这个业务在超市旁边一个房间里,由于忘记带小票,那个小房间的人让我去另外一个小房间调电脑里的记
- 在access中进行时间的比较sql语句很简单,如select * from table where thetime>#\"
- 在附加数据库后查看不了数据库关系图,也无法建立数据库关系图 我的解决方法如下: 1、设置兼容级别为90(2005为90)(2000为80)
- 一些很实用且必用的js小脚本代码:脚本1:进入页面后自动播放音乐或其它声音文件<embed src="音乐地址&q
- 环境:A机器和B机器都是LINUX系统,但由于B机器已经空间不足,所以停掉不停操作数据库的服务后 ,准备在A机器进行导出操作。导出语句 ex
- <%'***********************************************'函数