用 idhttp 取的天气预报

function TForm1.GetWeatherFromWeatherComCnWap(City: string): string;
  function StrToHexStr(const s: string): string;
  var
    temps: string;
    I: Integer;
  begin
    for I := 1 to Length(s) do
      temps := temps + '%' + inttohex(Ord(s[I]), 2);
    Result := temps;
  end;
  function CutString(sStringList: TStringList; City: string): string;
  var
    I, IndexofCity: Integer;
    s, s1, s2, s3: string;
  begin
    //ÄϾ© <img src="http://media.weather.com.cn/img/w/c3.gif" /> <img src="http://media.weather.com.cn/img/w/c3.gif" />
   //<br />
   //ÌìÆø£ºÕóÓê
   //<br />
   //ÆøÎ£º10¶Èµ½4¶È
   //<br />
   //·çÏò·çÁ¦£º¶«±±·ç4-5¼¶
   //<br />
    IndexofCity := -1;
    for I := 0 to sStringList.Count - 1 do begin
      if copy(sStringList.Strings[I], 1, Length(City)) = City then begin
        IndexofCity := I;
      end;
    end;
    s1 := sStringList.Strings[IndexofCity + 2];
    s2 := sStringList.Strings[IndexofCity + 4];
    s3 := sStringList.Strings[IndexofCity + 6];
    //
    s1 := copy(s1, POS('£º', s1) + 2, Length(s1));
    s2 := copy(s2, POS('£º', s2) + 2, Length(s2));
    s3 := copy(s3, POS('£º', s3) + 2, Length(s3));

    Result := s1 + ' ' + s2 + ' ' + s3;

  end;
var
  IdHTTPWeb: TIdHTTP;
  Response2: TStringStream;
  s, ss: string;
  sStringList: TStringList;
begin
  //
  IdHTTPWeb := TIdHTTP.Create(Self);
  sStringList := TStringList.Create;
  Response2 := TStringStream.Create('');
  //
  s := 'http://wap.weather.com.cn/wap/search/?city=' + StrToHexStr(AnsitoUtf8(Trim(City)));
  IdHTTPWeb.HandleRedirects := true;

  IdHTTPWeb.Request.ContentType := 'application/x-www-form-urlencoded';
  IdHTTPWeb.Get(s, Response2);
  s := Response2.DataString;
  s := Utf8ToAnsi(s);
  sStringList.Text := s;
  Result := CutString(sStringList, City);
  //
  Response2.Free;
  IdHTTPWeb.Free;
  sStringList.Free;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值