当前位置:编程学习 > Delphi >>

如何获取TWebBrowser控件的超级链接

procedure getAllLinks2(WB: TWebBrowser; var InnerText,Links: TStringList);
//needs unit as :shDocVw,Classes,MSHTML,variants
var
Htmldoc     : IHtmlDocument2;
AllLinks    : IhtmlElementCollection;
Len,I   : Integer;
//HtmlItem2    : Olevariant;
HtmlItem: IHTMLElement;

begin
 HtmlDoc := WB.document as Ihtmldocument2;
// AllLinks := HtmlDoc.get_links;
 AllLinks := HtmlDoc.links;
 Len := AllLinks.length ;
 Links.BeginUpdate;
 Innertext.BeginUpdate;
 For I :=0 To Len-1 do
 begin
 //HtmlItem2 := AllLinks.item(I,emptyparam);
 HtmlItem := AllLinks.item(I,emptyparam) as IHTMLElement;
 //StringList.Add(Htmlitem2.href);    //this is also a way to get the link


 {if trim(HtmlItem.innerHTML)<> then
 begin
 Links.Add(trim(HtmlItem.ToString));
 InnerText.Add(trim(HtmlItem.innerHTML));
 end;
 }

 if trim(HtmlItem.innerText)<> then
 begin
 Links.Add(trim(HtmlItem.ToString));
 InnerText.Add(trim(HtmlItem.Innertext));
 end;

 end;
 Links.EndUpdate;
 InnerText.EndUpdate;
end;

补充:软件开发 , Delphi ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,