日期:2014-05-17  浏览次数:20968 次

c#如何填写网页数据并自动登录
<table id="tbl001" cellspacing=10>
<tr>
<th align="left"><span class=labeltext>用户名</span></th>
<td align="left">
<input type="text"
   name="USERNAME"
   size=20
   onFocus="this.className='focusField';"
   onBlur="this.className='';">
</td>
</tr>

<th align=left>

<span class=labeltext>密码</span>

</th>
<td align="left">
<input type="password"
   name="PIN"
   size=20
   onFocus="this.className='focusField';"
   onBlur="this.className='';">
</td>
</tr>

</table>



我参照网上一些网友程序,用C#webBrowser控件的方法:


  foreach (HtmlElement em in log_auto.All)    
            {
            string str = em.Name;
                string id = em.Id;
                if ((str == "USERNAME") || (str == "PIN") || (str == "submit")) /  
 
                {
                    switch (str)
 
                    {
                        case "USERNAME": em.SetAttribute("value", "xiewei");
                            break;    
                        case "PIN": em.SetAttribute("value", "1");
                            break;  
                        default:

                            break;
 
                    }
                }



但是很奇怪“它打开界面后也还是无法输入用户名还密码。。。。”是不是这个控件里没有value值,不能用SetAttribute属性进行设置啊?我看了下,SetAttribute是设置“已有元素的属性值”

------解决方案--------------------
楼主参考这个