E
eaglepsm
Unregistered / Unconfirmed
GUEST, unregistred user!
“网页测试”这个链接可以提取,“网页辅助”链接就不行
c:/test.html
<html>
<head>
<title>test</title>
</head>
<body>
<a href=http://download.csdn.net/sort/tag/%E7%BD%91%E9%A1%B5%E8%BE%85%E5%8A%A9>网页辅助</a>|</p>
<a href=http://download.csdn.net/sort/tag/网页测试>网页测试</a>|</p>
</body>
</html>
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls,MSHTML;
type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1: TWebBrowser;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ 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;
begin
memo1.Clear;
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('c:/test.html');
end;
end.
c:/test.html
<html>
<head>
<title>test</title>
</head>
<body>
<a href=http://download.csdn.net/sort/tag/%E7%BD%91%E9%A1%B5%E8%BE%85%E5%8A%A9>网页辅助</a>|</p>
<a href=http://download.csdn.net/sort/tag/网页测试>网页测试</a>|</p>
</body>
</html>
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls,MSHTML;
type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1: TWebBrowser;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ 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;
begin
memo1.Clear;
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('c:/test.html');
end;
end.