delphi中TWebbrowser自动点击链接(枚举HTML元素)

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;


发表评论

您的电子邮箱地址不会被公开。

− 1 = 1