private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElementCollection links = this.webBrowser1.Document.Links;
foreach (HtmlElement link in links)
{
if (link.GetAttribute("href").Contains("google.com"))
{
link.InvokeMember("click");
}
}
}
///
/// 自动登录,适用于没有验证码的情况
///
/// <param name="userId" />登录的帐号 /// <param name="password" />登录的密码 private void AutoLogon(string userId, string password)
{
#region 获取登录FORM的输入框 和 Submit 按钮
HtmlElement textboxUserId = this.webBrowser1.Document.GetElementById("登录用户名文本框的ID");
HtmlElement textboxPassword = this.webBrowser1.Document.GetElementById("登录密码框的ID");
HtmlElement buttonSubmit = this.webBrowser1.Document.GetElementById("登录按钮的ID");
textboxUserId.SetAttribute("value", userId);
textboxPassword.SetAttribute("value", password);
buttonSubmit.InvokeMember("click");
#endregion
}