getfile.asp
<% ''应用xmlhttp组件猎取长途文件保存到当前空间 ''此是网站建设中的一个实例,长途猎取一个网页内容并挑选出相干的天气数据,固然能够跳过文件当地存储再猎取数据 ''参考了xoyu的函数,在此谢谢 fileurl="http://www.hbqx.gov.cn/other/tqyb/inc_city_hb.asp" dotloc=InStrRev(fileurl,".") filepath="thistest"&mid(fileurl,dotloc) ''竖立同范例文件名 ''filepath="thistest.htm" call saveRemoteFile(filepath,fileurl) sub SaveRemoteFile(LocalFileName,RemoteFileUrl) dim Ads,Retrieval,GetRemoteData Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP") With Retrieval .Open "Get", RemoteFileUrl, False, "", "" .Send GetRemoteData = .ResponseBody '' GetDetail = .ResponseText ''对文本型文件可直接猎取内容,但不能支撑中文,不知道怎样处理 End With Set Retrieval = Nothing ''RESPONSE.WRITE GetDetail Set Ads = Server.CreateObject("Adodb.Stream") ''生成对应文件 With Ads .Type = 1 .Open .Write GetRemoteData .SaveToFile server.MapPath(LocalFileName),2 .Cancel() .Close() End With Set Ads=nothing end sub ''以上完成长途存储文件,以下只适用于对文本型文件的操纵www.knowsky.com set fso=server.createobject("scripting.filesystemobject") ''读取文件内容 set fileout=fso.opentextfile(server.mappath(filepath),1) content=fileout.readall set fileout=nothing set fso=nothing ''response.write content contentarr=split(content,"<td") ''依据内容举行挑选 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 response.write "document.write('恩施州将来24小时天气预报:"&xu(1)&",最低温度"&xu(2)&"摄氏度,最高温度"&xu(3)&"摄氏度,风向:"&xu(4)&".--武汉中间气象台宣布');" else response.write "document.write('暂未宣布');" end if ''response.write server.htmlencode(str) %>
在另一个htm页中援用显现猎取内容
<script src="getfile.asp"></script>
以上就是详解xmlhttp组件猎取长途文件并挑选出目的数据的细致内容,更多请关注ki4网别的相干文章!