• 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");  

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

  • 相关阅读:
    华东交通大学2017年ACM双基程序设计大赛题解
    hdu2010(dfs+剪枝)
    欧拉函数phic以及超大数的快速幂
    想了一天的题目QAQ 毛线数列的最值
    记一下STL的一个题
    hdu1877进制转换
    hdu1002大数相加
    hdu1576逆元的一道水题
    Courses
    CodeForce-813B The Golden Age(数学+枚举)
  • 原文地址:https://www.cnblogs.com/friendwang1001/p/3878063.html
Copyright © 2020-2023  润新知