实现自动登录某网站,并且登录完成后跳转到指定的页面。然后进行表单的自动填充表单提交 。类型于小型的发帖机 哈哈 (看官在看下面代码的时候,把记得把下面的链接改下)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.Navigate("www.tiantianit.com");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.Url.ToString() == "www.tiantianit.com")
{
webBrowser1.Document.All["username"].InnerText = "tiantianit.com";
webBrowser1.Document.All["password"].InnerText = "tiantianit.com";
//webBrowser1.
HtmlElement tem = null;
var tem111 = webBrowser1.Document.GetElementsByTagName("input");
for (int i = 0; i < tem111.Count; i++)
{
HtmlElement aaaa = tem111[i];
if (aaaa.GetAttribute("type") == "button")
{
tem = aaaa;
}
}
tem.InvokeMember("click");
Thread.Sleep(1000);
webBrowser1.Navigate("www.tiantianit.com");//登陆成功后转到写blog
this.Show();
//bool isLogIn = false;
//if (webBrowser1.Url.ToString() == "www.tiantianit.com")
//{
// System.Windows.Forms.MessageBox.Show("用户名或密码错误!");
// return;
//}
//else
//{
// //isSetForm = false;
// //mylogin.Close();
// webBrowser1.Navigate("www.tiantianit.com");
// this.Show();
//}
}
if (webBrowser1.Url.ToString() == "www.tiantianit.com")
{
webBrowser1.Document.All["txtTitle"].InnerText = "hello 我的第一篇博客";
webBrowser1.Document.All["editor"].InnerText = "hello 我的第一篇博客";
//var tem111 = webBrowser1.Document.GetElementsByTagName("body");
//HtmlElement bbbb = null;
//for (int i = 0; i < tem111.Count; i++)
//{
// HtmlElement aaaa = tem111[i];
// if (aaaa.GetAttribute("class") == "editMode")
// {
// bbbb = aaaa;
// }
//}
//bbbb.InnerHtml = "hello 我的第一篇博客";
webBrowser1.Document.GetElementById("selType").SetAttribute("innerHTML", "转载");
webBrowser1.Document.GetElementById("txtTag2").InnerText = "asp.net";//标题
webBrowser1.Document.GetElementById("txtTag").InnerText = "asp.net";//内容
HtmlElement authortb = webBrowser1.Document.All["radChl2"];
authortb.SetAttribute("checked", "checked");
}
}
}