gpt4 book ai didi

html - 如何在 TImage 上显示 Div 背景图像

转载 作者:太空宇宙 更新时间:2023-11-04 16:06:51 25 4
gpt4 key购买 nike

我有一个应用程序可以从各个站点收集信息来填充我的数据库。我坚持这个 site有一个验证码。我需要为我的用户显示验证码。问题是图像位于 DIV 中的 background-image 中。

DIV idcaptchaCodigo

我知道如何通过 id 和名称获取元素,使用值等。但是我不知道如何获取这张图片或 url。

提前致谢

最佳答案

图像是 base64 编码 ,您需要将它从 html 代码中提取出来并将其转换为位图不要忘记发送 uuidCaptcha 与您的发布请求标识您在程序中输入的验证码的 ID。

uses Soap.EncdDecd, IdHTTP, System.StrUtils, pngimage;

Function _ExtractBetweenTags(Const s, LastTag, FirstTag: string; TrimTags: Boolean = True): string;
var
pLast,pFirst,pNextFirst : Integer;
begin
pFirst := Pos(FirstTag,s);
pLast := Pos(LastTag,s);
while (pLast > 0) and (pFirst > 0) do begin
if (pFirst > pLast) then // Find next LastTag
pLast := PosEx(LastTag,s,pLast+Length(LastTag))
else
begin
pNextFirst := PosEx(FirstTag,s,pFirst+Length(FirstTag));
if (pNextFirst = 0) or (pNextFirst > pLast) then begin
if TrimTags then begin
Result := Trim(StringReplace(Trim(Copy(s,pFirst,pLast-pFirst+Length(LastTag))), LastTag, '', [rfReplaceAll, rfIgnoreCase]));
Result := Trim(StringReplace(Result, FirstTag, '', [rfReplaceAll, rfIgnoreCase]));
end
else
Result := Trim(Copy(s,pFirst,pLast-pFirst+Length(LastTag)));
Exit;
end
else
pFirst := pNextFirst;
end;
end;
Result := '';
end;

procedure TForm4.btn1Click(Sender: TObject);
var
Input: TStringStream;
Output: TBytesStream;
sTmp, uuidCaptcha, captchaCodigo: string;
IdHTTP: TIdHTTP;
Graphic: TGraphic;
begin
IdHTTP := TIdHTTP.Create(nil);
try
IdHTTP.AllowCookies := True;
IdHTTP.HandleRedirects := True;
IdHTTP.Request.Connection := 'keep-alive';
IdHTTP.Request.UserAgent := 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36';
sTmp := IdHTTP.Get('http://www.tjms.jus.br/cpopg5/imagemCaptcha.do');
uuidCaptcha := _ExtractBetweenTags(sTmp, '"}', '"uuidCaptcha": "'); // You need this when you send the post request
captchaCodigo := _ExtractBetweenTags(sTmp, '", "labelValorCaptcha":', 'base64,');
mmo1.Lines.Add(captchaCodigo);
Input := TStringStream.Create(captchaCodigo, TEncoding.ASCII);
try
Output := TBytesStream.Create;
try
Soap.EncdDecd.DecodeStream(Input, Output);
Output.Position := 0;
Graphic := TPngImage.Create;
try
Graphic.LoadFromStream(Output);
img1.Picture.Bitmap.Assign(Graphic); // Your Image loads here
finally
Graphic.Free;
end;
finally
Output.Free;
end;
finally
Input.Free;
end;
finally
IdHTTP.Free;
end;
end;

关于html - 如何在 TImage 上显示 Div 背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37529456/

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