将这个放到调用页面上....一个处理地址函数..
function GetWebPage(URL: string):string;
var
IDHTTP: TIDHttp;
ss: String;
begin
IDHTTP:= TIDHTTP.Create(nil);
try
try
idhttp.Disconnect;
idhttp.HandleRedirects:= true; //必须支持重定向否则可能出错
idhttp.ReadTimeout:= 30000; //超过这个时间则不再访问
ss:=idhttp.Get(url);
//ss:=UTF8ToAnsi( ss); //UTF8编码转换
if IDHTTP.ResponseCode=200 then
Result := ss;
except
//ss:='';
end;
finally
IDHTTP.Free;
end;
end;
===========================================================
注意:
get百度时,需要修改http头:
User-Agent: Mozilla/3.0 (compatible; Indy Library)
因为百度屏蔽了 ‘Indy Library’ 这个客户端标识的。
本文介绍了一个用于从指定URL获取网页内容的函数实现,包括处理重定向和超时设置。特别强调了在访问特定网站如百度时,需要修改HTTP头以避免客户端标识被屏蔽的问题。
3352

被折叠的 条评论
为什么被折叠?



