PosEx() works perfectly without any problem. your question is wrong
Run this in your delphi, I don't see any problem.
Unit1.dfm
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 231
ClientWidth = 505
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object WebBrowser1: TWebBrowser
Left = 0
Top = 0
Width = 505
Height = 231
Align = alClient
TabOrder = 0
OnDownloadComplete = WebBrowser1DownloadComplete
ExplicitLeft = 120
ExplicitTop = 73
ExplicitWidth = 300
ExplicitHeight = 150
ControlData = {
4C00000031340000E01700000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
end
unit1.pas
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.OleCtrls, SHDocVw;
const
siteURL = 'https://www.leparisien.fr/societe/sante/covid-19-fin-de-la-periode-disolement-de-jean-castex-dont-lepouse-avait-ete-testee-positive-suivez-notre-direct-16-06-2021-BKACFU43MBAATAOLEN7BYHNNIY.php';
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormShow(Sender: TObject);
procedure WebBrowser1DownloadComplete(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses System.StrUtils, ActiveX;
function HTML_GetOGImage(HTML:String;var URL:String) : Boolean;
bar
I,A,B,C:Integer;
begin
Result:=False;
A := PosEx('og:image',HTML,1);
If A<>0 Then B:=PosEx('content="',HTML,A+9)Else Exit;
If B<>0 Then C:=PosEx('"',HTML,B+9)Else Exit;
URL := Copy(HTML, B+9, C-B-9); //I prefer <- instead of -> For I:=B+9 To C-1 Do URL:=URL+HTML[I];
ShowMessage('A = ' + IntToStr(A) +#13#10+ 'B = ' + IntToStr(B) +#13#10+ 'C = ' + IntToStr(C)); //remove this line after test
Result := True;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
WebBrowser1.Navigate(siteURL);
end;
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
var
LStream: TStringStream;
Stream : IStream;
LPersistStreamInit : IPersistStreamInit;
URL : String;
begin
if not Assigned(WebBrowser1.Document) then exit;
LStream := TStringStream.Create('');
try
LPersistStreamInit := WebBrowser1.Document as IPersistStreamInit;
Stream := TStreamAdapter.Create(LStream,soReference);
LPersistStreamInit.Save(Stream,true);
HTML_GetOGImage(LStream.DataString, URL);
finally
LStream.Free();
end;
end;
end.