gpt4 book ai didi

delphi - 如何将网页下载到变量中?

转载 作者:行者123 更新时间:2023-12-03 14:49:11 28 4
gpt4 key购买 nike

我不在乎它是否是字符串、字符串列表、备忘录等...但不是磁盘文件

如何将完整的网页下载到变量中?谢谢

最佳答案

使用 Indy:

uses IdHTTP;

const
HTTP_RESPONSE_OK = 200;

function GetPage(aURL: string): string;
var
Response: TStringStream;
HTTP: TIdHTTP;
begin
Result := '';
Response := TStringStream.Create('');
try
HTTP := TIdHTTP.Create(nil);
try
HTTP.Get(aURL, Response);
if HTTP.ResponseCode = HTTP_RESPONSE_OK then begin
Result := Response.DataString;
end else begin
// TODO -cLogging: add some logging
end;
finally
HTTP.Free;
end;
finally
Response.Free;
end;
end;

关于delphi - 如何将网页下载到变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9239267/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com