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;