xmlhttp组件获取远程文件并筛选出目标数据
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
''以上完成远程存储文件,以下只适用于对文本型文件的操作
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组件
相关阅读
- 05-06Centos6.3下Apache配置基于加密的认证https加密证书访问
- 03-23FTP客户端CuteFTP 使用图文教程
- 04-09Win7系统 msxml3.dll的问题!及解决方法!
- 11-19IIS 6.0 与IIS 7.0的HTTP压缩配置图文教程
- 11-19iis 6.0设置实现http转向 https的解决方案
- 02-28使用完美刷机对HTC Desire S进行刷机图文教程
- 04-17MiniSync FTP文件传输同步软件使用教程实现差异同步下载传功能
- 09-06TP-Link路由器设置图解
- 02-15通过IIS设置架设FTP服务器程序步骤
- 08-15命令行下改FTP密码
阅读本文后您有什么感想? 已有 人给出评价!
用户评论
热门评论
最新评论
相关软件
热点图文
- 02-16XML Schema学习笔记
- 06-14什么是 XML Web Service
- 02-16XML入门精解之结构与语法
- 06-19XML文档的基本操作
- 02-16ASP中查询数据库记录写入XML文件示例
- 02-16用XML和XSL来生成动态页面
- 02-07读写xml文件的2个小函数
- 02-16XML、Web服务和.NET框架
- 02-16XML的严格格式
- 06-13什么是XML