不会吧,用WebBrower的方式是可以的阿,下面是我刚写的例子,参考
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, ComCtrls, mshtml;
type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1: TWebBrowser;
ListView1: TListView;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch;
var URL: OleVariant);
private
FFinished: Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
doc: IHTMLDocument2;
all: IHTMLElementCollection;
len, i: integer;
item: OleVariant;
listitem: TListItem;
begin
if not FFinished then
ShowMessage('网页正在下载中……')
else 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);
listitem := ListView1.Items.Add;
listitem.Caption := item.href;
listitem.SubItems.Add(item.innertext);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.163.com');
FFinished := False;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
begin
FFinished := True;
end;
end.
窗体文件
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
BorderIcons = [biSystemMenu, biMinimize]
Caption = '获取网页所有链接示例'
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 12
object Button1: TButton
Left = 576
Top = 212
Width = 93
Height = 25
Caption = '获取连接'
TabOrder = 0
OnClick = Button1Click
end
object WebBrowser1: TWebBrowser
Left = 0
Top = 0
Width = 688
Height = 201
Align = alTop
TabOrder = 1
OnDocumentComplete = WebBrowser1DocumentComplete
ControlData = {
4C0000001B470000C61400000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
object ListView1: TListView
Left = 0
Top = 244
Width = 688
Height = 209
Align = alBottom
Columns = <
item
Caption = '连接地址'
Width = 350
end
item
Caption = '说明'
Width = 250
end>
TabOrder = 2
ViewStyle = vsReport
end
end