[英]How do I create an IHTMLDocument2 using a string from TIdHTTP?
I download a URL with IdHTTP.Get
, and I need to search the HTML tags and extract some data. 我使用
IdHTTP.Get
下载URL,并且需要搜索HTML标记并提取一些数据。
How I can convert the string that IdHTTP.Get
returns into an IHTMLDocument2
? 我怎么可以将字符串转换
IdHTTP.Get
返回到IHTMLDocument2
?
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 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.