TWebbrowser自动点击链接

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;

你可能感兴趣的:(Delphi学习笔记,delphi,url)