zoukankan      html  css  js  c++  java
  • Webbrowser中模拟连接点击(非鼠标模拟)

    Delphi

    [delphi] view plaincopy
     
    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 := to Anchors.length - 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;  

    C#(点击网易页面“新闻”链接)

    [csharp] view plaincopy
     
    1. foreach (HtmlElement element in webBrowser1.Document.Links)  
    2. {  
    3.     if (element.InnerText == "新闻")  
    4.     {  
    5.         element.InvokeMember("click");  
    6.         break;  
    7.     }  
    8. }  

    http://blog.csdn.net/bdmh/article/details/6069485

  • 相关阅读:
    Java的Regex --正则表达式
    Java的包装类
    类的始祖Object
    abstract和interface关键字介绍
    内部类
    Accumulation Degree [换根dp,二次扫描]
    牛客练习赛61 [口胡]
    CF1334G Substring Search [bitset,乱搞]
    CF1175F The Number of Subpermutations [哈希,乱搞]
    CF793G Oleg and chess [线段树优化建边,扫描线,最大流]
  • 原文地址:https://www.cnblogs.com/findumars/p/5001968.html
Copyright © 2011-2022 走看看