delphi通过解析搜狐网页来获取天气的函数  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi通过解析搜狐网页来获取天气的函数



function GetWeather(City: String): String;

 const

    sys01='';

    sys02='

    sys04='

';

 var

  tmpstr,str1:string;

  j:integer;

  vFileStream:TFileStream;

  http:tidhttp;

 begin

  http:=tidhttp.Create(nil);

  tmpstr:=http.Get('http://weather.news.sohu.com/citymake.php?city='+City);

  j:=pos(sys01,tmpstr);

  tmpstr:=copy(tmpstr,j,length(tmpstr));

  j:=pos(sys02, tmpstr);

  tmpstr:=copy(tmpstr,j+length(sys02),length(tmpstr));

  j:=pos(sys03,tmpstr);

  str1:=copy(tmpstr,0,j-1);


  //下载图片

   vFileStream:=TFileStream.Create(ExtractFilePath(application.ExeName)+'/weather.jpg',fmCreate,fmShareDenyNone);

   try

     //IdHTTP1.Get('http://173.16.80.26/inputdb.mdb',vFileStream);

     HTTP.Get(str1,vFileStream);

    //mage1.Picture.Bitmap.LoadFromStream(vfilestream);

   finally

    vFileStream.Free;

   end;//try..finally

  {sleep(1000);

  image1.Picture.LoadFromFile( ExtractFilePath(application.ExeName)+'/weather.jpg');

  }

  j:=pos(sys04,tmpstr);

  tmpstr:=copy(tmpstr, j+length(sys04),length(tmpstr));

  j:=pos(sys05,tmpstr);

  str1:=copy(tmpstr,0,j-1);

  str1:=stringreplace(str1,' ','',[rfreplaceall]);

  str1:=stringreplace(str1,chr(13),'',[rfreplaceall]);

  str1:=stringreplace(str1,chr(10),'',[rfreplaceall]);

  str1:=stringreplace(str1,'
','  ',[rfreplaceall]);

  http.Free;

  result:=str1;

 end;



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.053586006164551 seconds

';

    sys05='