如何得到网页中所有链接的内容和链接地址?(20分)

  • 主题发起人 主题发起人 SandWater
  • 开始时间 开始时间
S

SandWater

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,用delphi编程实现
 
我只知道取链接:(


uses mshtml

var
Document : IHtmlDocument2;
Link : IHTMLElement;
StrLinks : string;
i : integer;

begin
Document := WebBrowser1.Document as IHTMlDocument2;
for i := 0 to Document.Links.Length - 1 do
begin
Link := Document.Links.Item(i, 0) as IHTMLElement;
StrLinks := Link.ToString + #13#10;
ShowMessage(StrLinks);
end;
end;
 
可以了,我的代码如下:
var
Document: IHtmlDocument2;
Link: IHTMLElement;
href: IHTMLElement;
StrLinks, StrHref: string;
i: integer;
begin
Document := WebBrowser1.Document as IHTMlDocument2;
urlLink.Clear;
for i := 0 to Document.Links.Length - 1 do
begin
Link := Document.Links.Item(i, 0) as IHTMLElement;
href := Document.anchors.item(i, 0) as IHTMLElement;
StrLinks := Link.ToString;
StrHref := link.innerText;
if LowerCase(copy(StrLinks,0,4))='file' then Continue;
if LowerCase(copy(StrLinks,0,4))='mail' then Continue;
urlLink.AddEx(StrLinks + '::' + StrHref, true, true);
ProgressBar1.Position:=(ProgressBar1.Width*i) div Document.Links.Length;
end;

end;

给分了
 
接受答案了.
 
后退
顶部