C# 网页登录

来源:互联网 发布:fedora与ubuntu 编辑:程序博客网 时间:2024/05/17 03:14
//登录http://218.196.244.90:8080/dz1.php
winform界面一个button,一个textbox,一个webBrowser1.
 private void button1_Click(object sender, EventArgs e)        {            string sUrl = textBox1.Text.Trim();            if (sUrl.Length > 0)            {                webBrowser1.Navigate(sUrl);            }        }        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)        {            HtmlElement ClickBtn = null;            if (e.Url.ToString().ToLower().IndexOf("php") > 0)            {                HtmlDocument doc = webBrowser1.Document;                for (int i = 0; i < doc.All.Count; i++)                {                    if (doc.All[i].TagName.ToUpper().Equals("INPUT"))                    {                        switch (doc.All[i].Name)                        {                            case "T1":                                doc.All[i].InnerText = "311209";                                break;                            case "T3":                                doc.All[i].InnerText = "2***";                                 break;                            case "xm":                                doc.All[i].InnerText = "**";                                  break;                            case "B1":                                ClickBtn = doc.All[i];                                break;                        }                    }                }                ClickBtn.InvokeMember("Click");              }        }

0 0