• C# 网页自动填表自动登录(转)


    自动填表的方式有很多,关键是获取控件的id或者name。

    比如源代码有

    [xhtml] view plaincopy
     
    1. <input id="pwdInput" tabindex="2" class="ipt-t" type="password" name="password" onMouseOver="fEvent('mouseover',this)" onFocus="fEvent('focus',this)" onBlur="fEvent('blur',this)" onMouseOut="fEvent('mouseout',this)"/>  

    那么就可以用

    [xhtml] view plaincopy
     
    1. HtmlDocument doc = webBrowser1.Document;  
    2.                 foreach (HtmlElement em in doc.All)   
    3.         {  
    4.             string str = em.Id;  
    5.             if (str == "pwdInput")    
    6.             {  
    7.                 em.SetAttribute("value", "abc"); break;   
    8.                     
    9.             }  
    10.         }   

    foreach获得了全部的控件id,然后找出 id为pwdInput的控件并赋值abc。

    还可以更简单直接获取控件id,如下

    [xhtml] view plaincopy
     
    1. HtmlElement tbUserid = webBrowser.Document.All["username"];     
    2. HtmlElement tbPasswd = webBrowser.Document.All["password"];     
    3. tbUserid.SetAttribute("value", "");     
    4. tbPasswd.SetAttribute("value", "");     

    这样就自动找到id为usename 和password的控件并赋值。

    点击按钮也有很多种方式,如果知道按钮的id或者name,例如id为:"submitbutton",直接用

    [c-sharp] view plaincopy
     
    1. HtmlElement btnSubmit = webBrowser.Document.All["submitbutton"];     
    2.   
    3. btnSubmit.InvokeMember("click");  

    如果不知道id和name,就用

    [xhtml] view plaincopy
     
    1. webBrowser1.Document.Forms[0].Invoke("submit");  

    这样获取了所有该网页所有按钮连接

  • 相关阅读:
    C#即时释放内存
    NI Vision ClampRake修改
    CListCtrl颜色设置
    备份和vim编辑器的操作
    查看,统计,检索文件命令
    linux中find mv cp 等常用命令用法
    防止恶意用户登入linux服务器
    CentOS7 启动时出现:Redirecting to /bin/systemctl start httpd.service
    linux服务器常用命令
    14个支持响应式设计的前端框架
  • 原文地址:https://www.cnblogs.com/friendwang1001/p/3878063.html
Copyright © 2020-2023  润新知