C# winform的WebBrowser自动登录某网站
2017-09-15 15:08
549 查看
最近项目需要接入别人的系统,需要自动登录,大概思路是:自动填写给定的用户名密码,模拟点击登录按钮;
代码如下:
HtmlElement elmUserName = web.Document.GetElementById(UserNameField);
if (elmUserName != null) elmUserName.SetAttribute("value", UserNameValue);
HtmlElement elmPWD = web.Document.GetElementById(PasswordField);
if (elmPWD != null) elmPWD.SetAttribute("value", PasswordValue);
HtmlElementCollection hecs = web.Document.GetElementsByTagName("button");
foreach (HtmlElement hec in hecs)
{
if (hec.Name == loginButtonName)
{
HtmlElement login = hec;
if (login != null)
login.InvokeMember("click");
}
}
后来遇到有的网站用到了JQuery EasyUI的控件,无法使用上述方法自动登录,需要稍改一下
HtmlElement elmUserName = web.Document.GetElementById(UserNameField);
if (elmUserName != null) elmUserName.SetAttribute("value",UserNameValue);
HtmlElement elmPWD =PasswordField);
if (elmPWD != null) elmPWD.SetAttribute("value",PasswordValue);
HtmlElementCollection hec = web.Document.GetElementsByTagName("input");
foreach (HtmlElement he in hec)
{
if (he.Name == "Password")
{
he.SetAttribute("value",PasswordValue);
break;
}
}
HtmlElement loginHe = web.Document.GetElementById(AFieldName);
if (loginHe != null) loginHe.InvokeMember("click");
代码如下:
HtmlElement elmUserName = web.Document.GetElementById(UserNameField);
if (elmUserName != null) elmUserName.SetAttribute("value", UserNameValue);
HtmlElement elmPWD = web.Document.GetElementById(PasswordField);
if (elmPWD != null) elmPWD.SetAttribute("value", PasswordValue);
HtmlElementCollection hecs = web.Document.GetElementsByTagName("button");
foreach (HtmlElement hec in hecs)
{
if (hec.Name == loginButtonName)
{
HtmlElement login = hec;
if (login != null)
login.InvokeMember("click");
}
}
后来遇到有的网站用到了JQuery EasyUI的控件,无法使用上述方法自动登录,需要稍改一下
HtmlElement elmUserName = web.Document.GetElementById(UserNameField);
if (elmUserName != null) elmUserName.SetAttribute("value",UserNameValue);
HtmlElement elmPWD =PasswordField);
if (elmPWD != null) elmPWD.SetAttribute("value",PasswordValue);
HtmlElementCollection hec = web.Document.GetElementsByTagName("input");
foreach (HtmlElement he in hec)
{
if (he.Name == "Password")
{
he.SetAttribute("value",PasswordValue);
break;
}
}
HtmlElement loginHe = web.Document.GetElementById(AFieldName);
if (loginHe != null) loginHe.InvokeMember("click");
相关文章推荐
- winform c# 实现被访问的网站自动登录
- C# winform C/S WebBrowser 微信第三方登录
- Delphi WebBrowser Ole 自动登录网站
- C# winform C/S WebBrowser qq第三方授权登录
- C# winform 窗体接收命令行参数自动登录进行系统,模拟600个WCF客户端的并发压力测试
- c# 实现网页上用户自动登陆|asp.net 模拟网站登录
- WinForm : 利用webBrowser完成填充数据并 自动登陆某网站。。。。。。。
- C#自动登录网站(一)----WebBrowser
- C#发送HTTP请求自动登录Web网站
- (二)C# winform C/S WebBrowser qq第三方授权登录
- C#WinForm应用程序实现自动填充网页上的用户名和密码并点击登录按钮【转载】
- C#自动登录网站(二)----HttpWebRequest/HttpWebRespones
- (三)C# winform C/S WebBrowser 微博第三方授权登录
- Winform下动态执行JavaScript脚本获取运行结果,谈谈网站的自动登录及资料获取操作
- C#WinForm应用程序实现自动填充网页上的用户名和密码并点击登录按钮
- C#(WINFORM)实现模拟POST发送请求登录网站
- C# webBrowser 自动登录淘宝 模拟点击输入 模拟点击无ID 无name的html元素按钮
- Winform下动态执行JavaScript脚本获取运行结果,谈谈网站的自动登录及资料获取操作
- 使用WebBrowser自动登录阿里妈妈网站
- WinForm : 利用webBrowser完成填充数据并 自动登陆某网站。。。。。。。