My FAQ,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > Asp > 综合文章
xmlhttp组件获取远程文件并筛选出目标数据
作者:未知 时间:2005-03-26 12:12 出处:Blog 责编:MyFAQ
              摘要:暂无

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>

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 myfaq.com.cn All rights reserved. www.myfaq.com.cn 版权所有