xmlhttp组件获取远程文件并筛选出目标数据
来源:百度文库 编辑:神马文学网 时间:2024/04/27 00:29:50
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,"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页中引用显示获取内容
<%
‘‘利用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,"
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页中引用显示获取内容
xmlhttp组件获取远程文件并筛选出目标数据
用正则解析图片地址,并利用XMLHTTP组件将其保存
用正则解析图片地址,并利用XMLHTTP组件将其保存
ASP小偷(远程数据获取)程序的入门教程1
excel如何筛选出B列在A列数据中不重复的数据
Excel:数据筛选功能
asp取动态表单中数据并写入xml文件
Excel的数据筛选功能
远程下载文件
利用XMLHTTP无刷新自动实时更新数据.
2009年报筛选出的高送转股
一个小时筛选出30个绝好网站
2009年报筛选出的高送转股
Office组件轻松把文件转成文档
学会搜集与筛选目标客户资料 浏览文章 奇迹CRM
推荐获取数据的16 个网站
Excel:数据筛选功能-网络学院-中原硅谷网
巧妙清除本地和远程日志文件
用SendMessage获取目录下所有文件
用SendMessage获取目录下所有文件
最好的数据导出组件SMExport - 广东网盟
Web数据展现与处理的组件——DJFocus
公式选股法筛选出 - oatilil的日志 - 网易博客
利用Jakarta commons fileupload组件实现多文件上传