xmlhttp组件获取远程文件并筛选出目标数据
getfile.asp
<%
''利用【lì yòng】xmlhttp组件🙋获取远【huò qǔ yuǎn】程文件🙋保存到当前空间
''此是网站建设【zhàn jiàn shè】🚥中的一【zhōng de yī】个实例【gè shí lì】,远程获😮取一个🐼网页内【wǎng yè nèi】容并筛选🏔出相关【chū xiàng guān】的天气数据【shù jù】🕟,当然可以跳过【yǐ tiào guò】🗑文件🙋本地存储再获取🛺数据【shù jù】♊
''参考了xoyu的函数,在此感谢【xiè】🐅
fileurl="http://www.hbqx.gov.cn/other/tqyb/inc_city_hb.asp"
dotloc=InStrRev(fileurl,".")
filepath="thistest"&mid(fileurl,dotloc) ''建立同【jiàn lì tóng】类型文【lèi xíng wén】件🎵名
''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 ''对文本【duì wén běn】💉型文件🎵可直接【kě zhí jiē】获取内容,但不能支持中文,不知道【bú zhī dào】如何解决
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
''以上完成远程【chéng yuǎn chéng】🤭存储文【cún chǔ wén】件🙋,以下只【yǐ xià zhī】适用于【shì yòng yú】对文本【duì wén běn】💉型文件🎵的操作【de cāo zuò】🎙
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),"恩施【ēn shī】🗳") 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('恩施【ēn shī】🗳州未来【zhōu wèi lái】24小时天气预报:"&xu(1)&",最低温度【dù】🚴"&xu(2)&"摄氏度【dù】🙍,最高温👔度【dù】🚴"&xu(3)&"摄氏度【dù】🙍,风向:"&xu(4)&".--武汉中心气象台发布🐾');"
else
response.write "document.write('暂未发🌚布🐾');"
end if
''response.write server.htmlencode(str)
%>
在另一个htm页中引用显示获取内容
<script src="getfile.asp"></script>
关键词:xmlhttp组件
阅读本文后您有什么感想? 已有 人给出评价!
- 1
- 1
- 1
- 1
- 1
- 1