getfile.asp
<%
''Use xmlhttp component to obtain remote files and save them to the current space
''This is an example in website construction. Remotely obtain a web page content and filter out relevant weather data. Of course, you can skip local file storage and then obtain the data.
''Referenced xoyu's function, thanks here
fileurl=" http://www.hbqx.gov.cn/other/tqyb/inc_city_hb.asp "
dotloc=InStrRev(fileurl,".")
filepath="thistest"&mid(fileurl,dotloc) ''Create file names of the same type
''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 ''You can directly obtain the content of text files, but it cannot support Chinese. I don’t know how to solve it.
End With
Set Retrieval = Nothing
''RESPONSE.WRITE GetDetail
Set Ads = Server.CreateObject("Adodb.Stream") ''Generate the corresponding file
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
Set Ads=nothing
end sub
''The above completes the remote storage of files, the following is only applicable to the operation of text files www.downcodes.com
set fso=server.createobject("scripting.filesystemobject") ''Read file content
set fileout=fso.opentextfile(server.mappath(filepath),1)
content=fileout.readall
set fileout=nothing
set fso=nothing
''response.write content
contentarr=split(content,"<td") ''Filter based on content
for i=1 to ubound(contentarr)
if instr(contentarr(i),"Enshi") 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('Enshi Prefecture weather forecast for the next 24 hours:"&xu(1)&", minimum temperature"&xu(2)&"℃, maximum temperature"&xu(3)&"℃, wind direction:" &xu(4)&".--released by Wuhan Central Meteorological Observatory');"
else
response.write "document.write('Not yet released');"
end if
''response.write server.htmlencode(str)
%>
Quoting and displaying the obtained content in another htm page
<script src="getfile.asp"></script>