I download a URL with IdHTTP.Get
, and I need to search the HTML tags and extract some data.
How I can convert the string that IdHTTP.Get
returns into an IHTMLDocument2
?
I download a URL with IdHTTP.Get
, and I need to search the HTML tags and extract some data.
How I can convert the string that IdHTTP.Get
returns into an IHTMLDocument2
?
I Googled this problem and I can find a good code for this:
Idoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
try
IDoc.designMode := 'on';
while IDoc.readyState <> 'complete' do
Application.ProcessMessages;
v := VarArrayCreate([0, 0], VarVariant);
v[0] := MyHTML;
IDoc.Write(PSafeArray(System.TVarData(v).VArray));
IDoc.designMode := 'off';
while IDoc.readyState <> 'complete' do
Application.ProcessMessages;
ParseHTML(IDoc);
finally
IDoc := nil;
end;
Regards
IdHTTP
has the Get
method overload allowing you to receive response to stream (actually is used in the one returning you the string). –
Urbannal designMode
and Application.ProcessMessages
to check readyState
is not needed. You don't need to switch to designMode=on
in order to be able to write to a IHTMLDocument
. I strongly suggest you use @Keeper's code. –
Shuntwound IHTMLDocument2::write
line with Invalid argument
on Windows 7, Delphi 7 (Personal) with imported MSHTML type library. The very same happens with PSafeArray(VarArrayAsPSafeArray(VarArrayOf([HTMLWideString])))
. –
Urbannal document
as OleVariant
and create it via late binding, e.g.: document := CreateComObject(CLASS_HTMLDocument) as IDispatch
and simply use document.write(<WideString>)
. Maybe this is why I never encountered this problem(?)... –
Shuntwound IHTMLDocument2
interface. –
Urbannal Doc.Write
–
Opt Try this one:
uses
... Variants, MSHTML, ActiveX;
var Cache: string;
V: OleVariant;
Doc: IHTMLDocument2;
begin
...
Cache := IdHTTP.Get(url);
Doc := coHTMLDocument.Create as IHTMLDocument2; // create IHTMLDocument2 instance
V := VarArrayCreate([0,0], varVariant);
V[0] := Cache;
Doc.Write(PSafeArray(TVarData(v).VArray)); // write data from IdHTTP
// Work with Doc
end;
I Googled this problem and I can find a good code for this:
Idoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
try
IDoc.designMode := 'on';
while IDoc.readyState <> 'complete' do
Application.ProcessMessages;
v := VarArrayCreate([0, 0], VarVariant);
v[0] := MyHTML;
IDoc.Write(PSafeArray(System.TVarData(v).VArray));
IDoc.designMode := 'off';
while IDoc.readyState <> 'complete' do
Application.ProcessMessages;
ParseHTML(IDoc);
finally
IDoc := nil;
end;
Regards
IdHTTP
has the Get
method overload allowing you to receive response to stream (actually is used in the one returning you the string). –
Urbannal designMode
and Application.ProcessMessages
to check readyState
is not needed. You don't need to switch to designMode=on
in order to be able to write to a IHTMLDocument
. I strongly suggest you use @Keeper's code. –
Shuntwound IHTMLDocument2::write
line with Invalid argument
on Windows 7, Delphi 7 (Personal) with imported MSHTML type library. The very same happens with PSafeArray(VarArrayAsPSafeArray(VarArrayOf([HTMLWideString])))
. –
Urbannal document
as OleVariant
and create it via late binding, e.g.: document := CreateComObject(CLASS_HTMLDocument) as IDispatch
and simply use document.write(<WideString>)
. Maybe this is why I never encountered this problem(?)... –
Shuntwound IHTMLDocument2
interface. –
Urbannal Doc.Write
–
Opt © 2022 - 2024 — McMap. All rights reserved.