DELPHI获取网页内容

2024-12-27 07:08:30
推荐回答(1个)
回答1:

//试下用idhttp

uses IdHTTP;

function GetWebPage(const Url :string; IsUtf8 :Boolean = False):string;
var
idp :TIdHTTP;
begin
Result := '';
idp := TIdHTTP.Create(Application);
try
idp.HandleRedirects := True;
idp.Request.UserAgent := 'Mozilla/5.0';
Result := idp.Get(Url);
if IsUtf8 then
Result := Utf8ToAnsi(Result);
finally
FreeAndNil(idp);
end;
end;

//当网页编码是utf8时,第2个参数请为true,要不汉字会出现乱码
ShowMessage(GetWebPage(Load_web_update + '/SysUpFiles.htm'));