Delphi获取当前网页上所有链接


uses  MSHTML;

procedure TForm1.Button1Click(Sender: TObject);
var
  doc:IHTMLDocument2;
  all:IHTMLElementCollection;
  len,i:integer;
  item:OleVariant;
begin
  doc:=WebBrowser1.Document as IHTMLDocument2;
  all:=doc.Get_links;//doc.Links亦可
  len:=all.length;
  for i:=0 to len-1 do
  begin
    item:=all.item(i,varempty);//EmpryParam亦可
    memo1.lines.add(item.href);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  webbrowser1.Navigate('www.hi.baidu.com/hacklzt');
end;