delphi中TWebbrowser自动点击链接,其中TWebBrowser的Navigate方法并不完全等同于点击链接
procedure TForm1.btnClickUrlClick(Sender: TObject);
var
J:integer;
spDisp: IDispatch;
IDoc1: IHTMLDocument2;
ielc: IHTMLElementCollection ;
ihtml:IHTMLElement;
iane:IHTMLAnchorElement;
begin
WebNav.Document.QueryInterface(IHTMLDocument2,iDoc1);
ielc:=idoc1.Get_all;
for J:=0 to ielc.length-1 do
begin
Application.ProcessMessages;
spDisp := ielc.item(J, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLAnchorElement ,iane))then
begin
if iane.href='http://www.nq51.com/' then //这里我在网页里的url是http://www.nq51.com调用的时候自动加上了'/'需要注意一下
begin
ihtml:=ielc.item(J,0) as IHTMLElement;
ihtml.click;
end;
end;
end;
end;
procedure TForm1.btnClickUrlClick(Sender: TObject);
var
J:integer;
spDisp: IDispatch;
IDoc1: IHTMLDocument2;
ielc: IHTMLElementCollection ;
ihtml:IHTMLElement;
iane:IHTMLAnchorElement;
begin
WebNav.Document.QueryInterface(IHTMLDocument2,iDoc1);
ielc:=idoc1.Get_all;
for J:=0 to ielc.length-1 do
begin
Application.ProcessMessages;
spDisp := ielc.item(J, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLAnchorElement ,iane))then
begin
if iane.href='http://www.nq51.com/' then //这里我在网页里的url是http://www.nq51.com调用的时候自动加上了'/'需要注意一下
begin
ihtml:=ielc.item(J,0) as IHTMLElement;
ihtml.click;
end;
end;
end;
end;
本文介绍了一种使用Delphi通过TWebBrowser组件自动点击网页链接的方法。通过获取网页元素并判断链接地址来实现指定链接的自动点击。

被折叠的 条评论
为什么被折叠?



