Webbrowser中模拟连接点击(非鼠标模拟)

  1. uses  
  2.   mshtml, ActiveX;  
  3.   
  4. //初始加载网易主页  
  5. procedure TForm1.FormCreate(Sender: TObject);  
  6. begin  
  7.   Webbrowser1.Navigate('http://www.163.com/');  
  8. end;  
  9.   
  10. procedure TForm1.Button1Click(Sender: TObject);  
  11. var  
  12. I: Integer;  
  13. Document: IHTMLDocument2;  
  14. Element: IHTMLElement;  
  15. Anchors: IHTMLElementCollection;  
  16. sLink: string;  
  17. begin  
  18.    //查找网易新闻页面链接  
  19.    sLink := 'http://news.163.com/';  
  20.    Document := Webbrowser1.Document as IHTMLDocument2;  
  21.    if Assigned(Document) then  
  22.    begin  
  23.       Anchors := Document.Get_links;  
  24.       //遍历所有链接  
  25.       for i := 0 to Anchors.length - 1 do  
  26.       begin  
  27.          Element := Anchors.item(i, varempty) as IHTMLElement;  
  28.          //找到指定链接  
  29.          if Assigned(Element) and (UpperCase((Element as IHTMLAnchorElement).href) = UpperCase(sLink)) then  
  30.         begin  
  31.            //执行点击  
  32.            Element.Click;  
  33.            Break;  
  34.         end;  
  35.       end;  
  36.    end;  
  37. end;  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值