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;
新闻热点
疑难解答