日期:2014-05-19  浏览次数:21055 次

【模拟登陆网站】如何在WebBrowser控件中,自动录入账号与密码,并自动确认登陆?(急)


http://www.s1166.com/

+++++++++++++++++++++++++++++++
如以上网站,如何在WebBrowser控件中显示,并且自动赋予账号与密码(可摸似)


因为login.php登陆页是套在首页的框架中,有些难度,期待各位兄弟的指点。谢谢



------解决方案--------------------
可以看看这里
http://community.csdn.net/Expert/topic/5624/5624377.xml?temp=.6301538
我的解答..

里面有如何 使用模拟登陆身份验证以及头信息欺骗
------解决方案--------------------
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html

CSDN阅读器 源码 登陆 部分

有你需要的.

------解决方案--------------------
private HtmlElement FindControlByName(string name, HtmlElementCollection listOfHtmlControls)
{
foreach (HtmlElement element in listOfHtmlControls)
{
if (!string.IsNullOrEmpty(element.OuterHtml))
{
if (element.Name == name.Trim())
{
return element;
}
}
}

return null;
}

private HtmlElement FindControlByTag(string tag, HtmlElementCollection listOfHtmlControls)
{
foreach (HtmlElement element in listOfHtmlControls)
{
if (!string.IsNullOrEmpty(element.OuterHtml))
{
if (element.TagName == tag.Trim())
{
return element;
}
}
}

return null;
}

HtmlElement textBox = this.FindControlByName( "TextBoxUserName ", this.webBrowser.Document.All);

textBox.InnerText = "UserName ";
------解决方案--------------------
HTMLDocument doc = webBrowser1.Document.DomDocument as HTMLDocument;

// <INPUT maxLength= "256 " size= "55 " name= "userid ">
//
HTMLInputElement textBox = (HTMLInputElement)doc.all.item( "userid ", 0);
textBox.value = "userid ";

// <INPUT type=submit value= "I 'm Feeling Lucky " name=btnI>
//
HTMLInputElement button = (HTMLInputElement)doc.all.item( "btnI ", 0);
button.click();

------解决方案--------------------
下面这段代码用来登录新浪免费Mail, 测试通过
HTMLDocument doc = webBrowser1.Document.DomDocument as HTMLDocument;
// <input name= "u " id= "u " type= "text " onfocus= "shy_clear() "/> 登录名
HTMLInputElementClass input = doc.all.item( "u ", 0) as HTMLInputElementClass;
input.value = "我的用户名 ";

// <input name= "psw " id= "psw " type= "password "/> 密码
input = doc.all.item( "psw ", 0) as HTMLInputElementClass;
input.value = "我的密码 ";

// <input type= "submit " value= "登录 " onclick= "return log_submit(); " align= "absmiddle "/> 登录
// <form name= "login " method= "post " action= " ">
webBrowser1.Document.InvokeScript( "log_submit ");

HTMLFormElementClass form = doc.all.item( "login ", 0) as HTMLFormElementClass;