特色栏目

ASP源码

PHP源码

.NET源码

JSP源码

游戏频道
专题合集
关闭菜单
首页> ASP教程> xmlhttp组件获取远程文件并筛选出目标数据

xmlhttp组件获取远程文件并筛选出目标数据

时间:2009-06-24 17:27:48 作者:互联网

ge***le.asp
<%
''利用xmlhttp组件获取远程文件保存到当前空间
''此是网站建设中的一个实例,远程获取一个网页内容并筛选出相关的天气数据,当然可以跳过文件本地存储再获取数据
''参考了xoyu的函数,在此感谢
fileurl="http://www.hbqx.gov.cn/other/tqyb/inc_city_hb.asp"
dotloc=InStrRev(fileurl,".")
filepath="thistest"&mid(fileurl,dotloc) ''建立同类型文件名
''filepath="th***est.htm"

call saveRemoteFile(filepath,fileurl)

sub SaveRemoteFile(LocalFileName,RemoteFileUrl)
dim Ads,Retrieval,GetRemoteData
Set Retrieval = Se***r.CreateObject("Mi***soft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody
'' GetDetail = .ResponseText ''对文本型文件可直接获取内容,但不能支持中文,不知道如何解决
End With

Set Retrieval = Nothing
''RE***NSE.WRITE GetDetail

Set Ads = Se***r.CreateObject("Ad***.Stream") ''生成对应文件
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile se***r.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
Set Ads=nothing
end sub

''以上完成远程存储文件,以下只适用于对文本型文件的操作www.downcodes.com
set fs***erver.createobject("sc***ting.filesystemobject") ''读取文件内容
set fi***ut=fso.opentextfile(se***r.mappath(filepath),1)
co***nt=fileout.readall
set fileout=nothing
set fso=nothing
''re***nse.write content

contentarr=split(content,"for i=1 to ubound(contentarr)
if instr(contentarr(i),"恩施") then thisloc=i
next
dim xu(5)
for j=0 to 4
con1=contentarr(thisloc+j)
start1=instr(con1,">")
con1=right(con1,len(con1)-start1)
stop1=instr(con1,"<")
con1=left(con1,stop1-1)
str=str&contentarr(thisloc+j)
xu(j)=trim(con1)
next
if xu(1)<>"" then
re***nse.write "do***ent.write('恩施州未来24小时天气预报:"&xu(1)&",最低温度"&xu(2)&"摄氏度,最高温度"&xu(3)&"摄氏度,风向:"&xu(4)&".--武汉中心气象台发布');"
else
re***nse.write "do***ent.write('暂未发布');"
end if
''re***nse.write se***r.htmlencode(str)
%>

在另一个htm页中引用显示获取内容

相关文章 最新文章

相关应用

热门文章

猜你喜欢

返回顶部