Asp.net WebBrowser webpage code

Source: Internet
Author: User

Asp tutorial. net webbrowser webpage code
Use fiddle to intercept the url and data sent to the server, and use the httprequest class code to post to the server.
Another method provided today is to use the webbrowser control in the winform control to operate the page.

Here we will simulate a search process, open the Baidu website, enter the search keyword, and open the connection in the search results

Public form1 ()
{
Initializecomponent ();
(Webbrowser1.activexinstance as shdocvw. webbrowser). navigatecomplete2 + =
New shdocvw. dwebbrowserevents2_navigatecomplete2eventhandler (form1_navigatecomplete2 );
}
Void form1_navigatecomplete2 (object pdisp, ref object url)
{
Ihtmldocument2 doc = (webbrowser1.activexinstance as shdocv?webbrowser=.doc ument as ihtmldocument2;
Doc.parentwindow.exe cscript ("window. alert = null", "webpage effect ");
Doc.parentwindow.exe cscript ("window. confirm = null", "javascript ");
Doc.parentwindow.exe cscript ("window. open = null", "javascript ");
Doc.parentwindow.exe cscript ("window. showmodaldialog = null", "javascript ");
Doc.parentwindow.exe cscript ("window. close = null", "javascript ");
}


The code is written here and submitted for search. webbrowser will also receive the record after this submission. Next we need to open a connection in the result to do the experiment.
First, check the html source code of the search result.

Private void webbrowserappsdocumentcompleted (object sender, webbrowserdocumentcompletedeventargs e)
{
Htmldocument doc = this.webbrowser1.doc ument;
If (doc. url. absoluteuri = "http://www.baidu.com /")
{
Doc. getelementbyid ("kw"). innertext = "Weng Yuli ";
Doc. getelementbyid ("su"). invokemember ("click ");
}
If (doc. url. absoluteuri. contains ("wd ") //
{
Htmlelement table = doc. getelementbyid ("1"); // locate the url of the first search result based on the html table of the search result.
Var html = table. children [0]. children [0]. innerhtml;
Var url = html. substring (html. indexof ("href") + 6, html. indexof ("target "));
This. webbrowser1.navigate (url );
}
}

 

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.