首页 >> XML/WebService >> 正文
XML HTTP组件获取远程文件并筛选出目标数据
来源:Dotnet频道 作者:采集 时间:2008-3-31


  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>
相关新闻
相关评论
 
评论表单加载中...
 
XML/WebService文章

 在Visual C++应

 编辑:admin

 时间:2008-3-10


   .NET Framework 中多语言支持的实现-.NET Framework
   将Eiffel系统集成到.NET Framework中-.NET Framework
   04年五种常用RAD的测验比较(1)-.NET Framework
   04年五种常用RAD的测验比较(2)-.NET Framework
   04年五种常用RAD的测验比较(3)-.NET Framework
最新文章
   .NET Framework 中多语言支持的实现-.NET Framework
   将Eiffel系统集成到.NET Framework中-.NET Framework
   04年五种常用RAD的测验比较(1)-.NET Framework
   04年五种常用RAD的测验比较(2)-.NET Framework
   04年五种常用RAD的测验比较(3)-.NET Framework
总站搜索
搜索
 
热门文章
   oracle数据库文件中的导入\导出
   用Oracle10g列值掩码技术隐藏敏感数据
   VB程序中用ADO对象动态创建数据库和表-VB.NET
   用VB6写简单程序 让电骡自动关机-VB.NET
   使用.NET2.0编写COM组件供VB调用-VB.NET
   VB.NET:键盘控制焦点移动-VB.NET
   用VB.NET绘制GDI图形-VB.NET
   vb.net中应用 ArrayList 实例-VB.NET
 
推荐文章
ASP.NET中的状态管理-ASP.NET
VC、IE、ASP环境下打印、预备的完美解决方案
oracle数据库文件中的导入\导出
VB.NET中快速访问注册表技巧-VB.NET
在vb中实现超连接的方法!和直接发邮件-VB.NET
用VB做realplayer播放列表-VB.NET
在VB.NET中如何实现和利用SortedLists-VB.NET
利用VB.NET Stopwatch对象记录时间-VB.NET
成都古羌科技有限公司版权所有: Copyright@2007-2010 ,ALL Rights Reserved 蜀ICP备07017240号