本文整理自网络,侵删。
uses mshtml, ActiveX;
//初始加载主页procedure TForm1.FormCreate(Sender: TObject);begin Webbrowser1.Navigate('http://www.hao828.com/');end;
procedure TForm1.Button1Click(Sender: TObject);varI: Integer;Document: IHTMLDocument2;Element: IHTMLElement;Anchors: IHTMLElementCollection;sLink: string;begin //查找页面链接 sLink := 'http://www.hao828.com/'; Document := Webbrowser1.Document as IHTMLDocument2; if Assigned(Document) then begin Anchors := Document.Get_links; //遍历所有链接 for i := 0 to Anchors.length - 1 do begin Element := Anchors.item(i, varempty) as IHTMLElement; //找到指定链接 if Assigned(Element) and (UpperCase((Element as IHTMLAnchorElement).href) = UpperCase(sLink)) then begin //执行点击 Element.Click; Break; end; end; end;end;
相关阅读 >>
Delphi datasnap中间件如何控制长连接的客户端连接?
winapi 字符及字符串函数(6): ischaralphanumeric - 是否是个文字(字母或数字)
Delphi 解决idtcpclient和idtcpserver通信中文乱码问题
更多相关阅读请进入《Delphi》频道 >>