标签:addition builder _id mem tostring rss 脚本 fresh form表单
常用的方法
1 Navigate(string urlString):浏览urlString表示的网址 2 Navigate(System.Uri url):浏览url表示的网址 3 Navigate(string urlString, string targetFrameName, byte[] postData, string additionalHeaders): 浏览urlString表示的网址,并发送postData中的消息 4 //(通常我们登录一个网站的时候就会把用户名和密码作为postData发送出去) 5 GoBack():后退 6 GoForward():前进 7 Refresh():刷新 8 Stop():停止 9 GoHome():浏览主页 10 WebBrowser控件的常用属性: 11 Document:获取当前正在浏览的文档 12 DocumentTitle:获取当前正在浏览的网页标题 13 StatusText:获取当前状态栏的文本 14 Url:获取当前正在浏览的网址的Uri 15 ReadyState:获取浏览的状态 16 WebBrowser控件的常用事件: 17 DocumentTitleChanged, 18 CanGoBackChanged, 19 CanGoForwardChanged, 20 DocumentTitleChanged, 21 ProgressChanged, 22 ProgressChanged 23 DocumentCompleted 页面加载完成之后的事件
获取非input控件的值
1 webBrowser1.Document.All["控件ID"].InnerText; 2 或webBrowser1.Document.GetElementById("控件ID").InnerText; 3 或webBrowser1.Document.GetElementById("控件ID").GetAttribute("value");
屏蔽脚本错误:
将WebBrowser控件ScriptErrorsSuppressed设置为True即可
获取元素、表单
1 //根据Name获取元素 2 public HtmlElement GetElement_Name(WebBrowser wb,string Name) 3 { 4 HtmlElement e = wb.Document.All[Name]; 5 return e; 6 } 7 8 //根据Id获取元素 9 public HtmlElement GetElement_Id(WebBrowser wb, string id) 10 { 11 HtmlElement e = wb.Document.GetElementById(id); 12 return e; 13 } 14 15 //根据Index获取元素 16 public HtmlElement GetElement_Index(WebBrowser wb,int index) 17 { 18 HtmlElement e = wb.Document.All[index]; 19 return e; 20 } 21 22 //获取form表单名name,返回表单 23 public HtmlElement GetElement_Form(WebBrowser wb,string form_name) 24 { 25 HtmlElement e = wb.Document.Forms[form_name]; 26 return e; 27 } 28 29 30 //设置元素value属性的值 31 public void Write_value(HtmlElement e,string value) 32 { 33 e.SetAttribute("value", value); 34 } 35 36 //执行元素的方法,如:click,submit(需Form表单名)等 37 public void Btn_click(HtmlElement e,string s) 38 { 39 40 e.InvokeMember(s); 41 }
1 [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] 2 static extern bool InternetGetCookieEx(string pchUrl, string pchCookieName, StringBuilder pchCookieData, ref System.UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved); 3 private static string GetCookieString(string url) 4 { 5 uint datasize = 1024; 6 StringBuilder cookieData = new StringBuilder((int)datasize); 7 if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x2000, IntPtr.Zero)) 8 { 9 if (datasize < 0) 10 return null; 11 cookieData = new StringBuilder((int)datasize); 12 if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, IntPtr.Zero)) 13 return null; 14 } 15 return cookieData.ToString(); 16 } 17 private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e) 18 { 19 richTextBox1.Text = string.Empty; 20 if (cbcookie.Checked) 21 { 22 if (checkBox1.Checked) 23 { 24 richTextBox1.Text = GetCookieString(textBox1.Text.Trim()); 25 } 26 else 27 { 28 richTextBox1.Text = webBrowser1.Document.Cookie; 29 } 30 } 31 } 32
标签:addition builder _id mem tostring rss 脚本 fresh form表单
原文地址:http://www.cnblogs.com/endv/p/5991668.html