C#webbrowser control using tutorials and tips for collecting

Source: Internet
Author: User

Common methods

1Navigate (stringurlstring): Browse urlstring-represented URLs2 Navigate (system.uri URL): Browse URLs represented by URL3Navigate (stringURLString,stringTargetframename,byte[] PostData,stringadditionalheaders): Browse urlstring represented URLs and send messages in PostData4 //(usually when we log in to a website, we send the username and password as postdata.)5 GoBack (): Back6 GoForward (): Forward7 Refresh (): Refreshing8 Stop (): Stop9 gohome (): Browse HomeTen Common properties of the WebBrowser control: One Document: Get the documents currently being browsed A documenttitle: Gets the title of the page currently being browsed - statustext: Gets the text of the current status bar - URL: Gets the URI of the URL currently being browsed the ReadyState: Get the status of the browse - Common events for WebBrowser controls: - documenttitlechanged, - cangobackchanged, + cangoforwardchanged, - documenttitlechanged, + ProgressChanged, A progresschanged atDocumentCompleted events After page load is complete

Get the value of a non-input control

1 webbrowser1.document.all[" control ID"]. InnerText; 2 or WebBrowser1.Document.GetElementById (" control ID"). InnerText; 3 or WebBrowser1.Document.GetElementById (" control ID"). GetAttribute ("value");

屏蔽脚本错误: 将WebBrowser控件ScriptErrorsSuppressed设置为True即可

Get elements, forms

1 //get elements by name2  PublicHtmlElement Getelement_name (WebBrowser WB,stringName)3 {4HtmlElement e =WB. Document.all[name];5     returne;6 }7  8 //get elements by ID9  PublicHtmlElement getelement_id (WebBrowser WB,stringID)Ten { OneHtmlElement e =WB. document.getElementById (ID); A     returne; - } -   the //get elements based on index -  PublicHtmlElement Getelement_index (WebBrowser WB,intindex) - { -HtmlElement e =WB. Document.all[index]; +     returne; - } +   A //get form table sole name name, return form at  PublicHtmlElement Getelement_form (WebBrowser WB,stringform_name) - { -HtmlElement e =WB. Document.forms[form_name]; -     returne; - } -   in   - //set the value of the element Value property to  Public voidWrite_value (HtmlElement E,stringvalue) + { -E.setattribute ("value", value); the } *   $ //methods of executing elements, such as: Click,submit (requires form table sole name), etc.Panax Notoginseng  Public voidBtn_click (HtmlElement E,strings) - { the   + E.invokemember (s); A}

1[DllImport ("Wininet.dll", CharSet = CharSet.Auto, SetLastError =true)]2       Static extern BOOLInternetgetcookieex (stringPchurl,stringPchcookiename, StringBuilder Pchcookiedata,refSystem.UInt32 Pcchcookiedata,intdwFlags, IntPtr lpreserved);3       Private Static stringGetcookiestring (stringURL)4       {5           UINTDataSize =1024x768;6StringBuilder Cookiedata =NewStringBuilder ((int) datasize);7           if(! Internetgetcookieex (URL,NULL, Cookiedata,refDataSize,0x2000, IntPtr.Zero))8           {9               if(DataSize <0)Ten                   return NULL; OneCookiedata =NewStringBuilder ((int) datasize); A               if(! Internetgetcookieex (URL,NULL, Cookiedata,refDataSize,0x00002000, IntPtr.Zero)) -                   return NULL; -           } the           returncookiedata.tostring (); -       } -       Private voidWebbrowser1_documentcompleted_1 (Objectsender, WebBrowserDocumentCompletedEventArgs e) -       { +richTextBox1.Text =string. Empty; -           if(Cbcookie. Checked) +           { A               if(checkbox1.checked) at               { -richTextBox1.Text =getcookiestring (TextBox1.Text.Trim ()); -               } -               Else -               { -richTextBox1.Text =WebBrowser1.Document.Cookie; in               } -           } to       } +       

C#webbrowser control using tutorials and tips for collecting

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.