WebBorwser访问Windows验证的网站 WebBrowser访问Windows验证网站问题。 弹出输入登录Windows的帐号和密码的框。请问如何在代码中实现自动登录后,访问网页? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 集成身份验证HtmlElement btnSubmit = webBrowser.Document.All["submitbutton"]; HtmlElement tbUserid = webBrowser.Document.All["username"]; HtmlElement tbPasswd = webBrowser.Document.All["password"]; tbUserid.SetAttribute("value", ""); tbPasswd.SetAttribute("value", ""); btnSubmit.InvokeMember("click"); 既然已经登录了那不就可以直接访问了吗 WebBrowser。navigate 是没有登录的,只是WebBrowser访问的不是登录页面,是网站中的其他页面。 但是如果当前的系统用户是登录的域用户的话访问是没有问题的,但是没有登录域的用户访问就有会弹出那个框出来 使用如下代码: class AutoVisit { /// <summary> /// 开始执行 /// </summary> /// <param name="mainUrl">主页面地址</param> /// <param name="client">WebClient对象</param> public void Start(string mainUrl, WebClient client) { string sUrl = ParseCurrentUrl(mainUrl); Queue<string> que = new Queue<string>(); que.Enqueue(mainUrl); while (que.Count > 0) { string h = que.Dequeue(); h = h.ToLower(); if (h.IndexOf("http://") == -1) { h = sUrl + h; } else { sUrl = ParseCurrentUrl(h); } string shtml = DownloadData(h, client); string[] subs = ParseForIframe(shtml); foreach (string s in subs) { string ss = s; if (s.IndexOf("http://") == -1) { ss = sUrl + s; } que.Enqueue(ss); } } } private string ParseCurrentUrl(string url) { url = url.ToLower(); Regex rx = new Regex(@"^http://(.*)?/"); string tmp = rx.Match(url).Value; return tmp; } private string DownloadData(string url, WebClient client) { if (string.IsNullOrEmpty(url)) return ""; byte[] data = client.DownloadData(url); string shtml = System.Text.Encoding.Default.GetString(data); return shtml; } private string[] ParseForIframe(string html) { html = html.ToLower(); List<string> iframeList = new List<string>(); Regex rx = new Regex(@"<iframe(.+)? src=[""|'](.*)[""|'](.+)?</iframe>"); MatchCollection mc = rx.Matches(html); foreach (Match m in mc) { GroupCollection gh = m.Groups; if (gh.Count > 0) { string tmp = gh[2].Value; if (!string.IsNullOrEmpty(tmp)) iframeList.Add(tmp); } } return iframeList.ToArray(); } } 读取文件 问题 这个代表什么意思呀! 高分求救!axRealAudio全屏后没有控制条。如何加上控制条【【【200分!】】】 求系统演示文稿! 初学者碰到时间计算的问题,在线等!~~~~~~~ C#修改已有内容文档的字体大小,页面大小 TransactionScope报错:“不确定事务”。。。。 TextBox透明 怎样在表里插入一条记录?用C#作数据库应用很烦! 用户控件 有没有办法调用form1里面的非静态的成员函数呢? C# 有现成的函数或正规表达式吗? 字符串加密问题
HtmlElement btnSubmit = webBrowser.Document.All["submitbutton"];
HtmlElement tbUserid = webBrowser.Document.All["username"];
HtmlElement tbPasswd = webBrowser.Document.All["password"];
tbUserid.SetAttribute("value", "");
tbPasswd.SetAttribute("value", "");
btnSubmit.InvokeMember("click");
但是如果当前的系统用户是登录的域用户的话访问是没有问题的,但是没有登录域的用户访问就有会弹出那个框出来
class AutoVisit
{
/// <summary>
/// 开始执行
/// </summary>
/// <param name="mainUrl">主页面地址</param>
/// <param name="client">WebClient对象</param>
public void Start(string mainUrl, WebClient client)
{
string sUrl = ParseCurrentUrl(mainUrl);
Queue<string> que = new Queue<string>();
que.Enqueue(mainUrl); while (que.Count > 0)
{
string h = que.Dequeue();
h = h.ToLower();
if (h.IndexOf("http://") == -1)
{
h = sUrl + h;
}
else
{
sUrl = ParseCurrentUrl(h);
}
string shtml = DownloadData(h, client);
string[] subs = ParseForIframe(shtml);
foreach (string s in subs)
{
string ss = s;
if (s.IndexOf("http://") == -1)
{
ss = sUrl + s;
}
que.Enqueue(ss);
} }
}
private string ParseCurrentUrl(string url)
{
url = url.ToLower();
Regex rx = new Regex(@"^http://(.*)?/");
string tmp = rx.Match(url).Value;
return tmp;
}
private string DownloadData(string url, WebClient client)
{
if (string.IsNullOrEmpty(url)) return "";
byte[] data = client.DownloadData(url);
string shtml = System.Text.Encoding.Default.GetString(data);
return shtml;
} private string[] ParseForIframe(string html)
{
html = html.ToLower(); List<string> iframeList = new List<string>();
Regex rx = new Regex(@"<iframe(.+)? src=[""|'](.*)[""|'](.+)?</iframe>");
MatchCollection mc = rx.Matches(html);
foreach (Match m in mc)
{
GroupCollection gh = m.Groups;
if (gh.Count > 0)
{
string tmp = gh[2].Value;
if (!string.IsNullOrEmpty(tmp))
iframeList.Add(tmp);
}
}
return iframeList.ToArray();
}
}