“取网页中所有链接”源码
unit Unit1;
inte易做图ce
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
GroupBox1: TGroupBox;
WebBrowser1: TWebBrowser;
Button1: TButton;
GroupBox2: TGroupBox;
ListBox1: TListBox;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DownloadBegin(Sender: TObject);
procedure WebBrowser1DownloadComplete(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
url:string;
begin
url:=edit1.Text ;
webbrowser1.Navigate(url); //打开网页
end;
procedure TForm1.WebBrowser1DownloadBegin(Sender: TObject);
begin
StatusBar1.Panels[0].Text :=正在打开网页/读取链接...;
end;
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject); //待网页打开完成再读取链接
var
i,n:integer;
begin
for i:=0 to WebBrowser1.OleObject.document.links.length-1 do
listBox1.Items.Add(WebBrowser1.OleObject.document.links.item(i).href); //读取链接
n:=WebBrowser1.OleObject.document.links.length; //链接数
StatusBar1.Panels[0].Text :=网页打开完毕!+[+inttostr(n)+个链接];
end;
end.
补充:综合编程 , 安全编程 ,