asp.net WebBrowser Operation page code

Source: Internet
Author: User

Use fiddle to intercept URLs and data that are post to the server, and post to the server using HttpRequest class code
Another way to do this today is to use the WebBrowser control in the WinForm control to manipulate the page.

Here we will simulate a search process, open the Baidu site, enter search keywords, in search results to open the connection

The code is as follows Copy Code
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 Shdocvw.webbrowser). Document as IHTMLDocument2;
Doc.parentwindow.execscript ("Window.alert=null", "web Effects");
Doc.parentwindow.execscript ("Window.confirm=null", "JavaScript");
Doc.parentwindow.execscript ("Window.open=null", "JavaScript");
Doc.parentwindow.execscript ("Window.showmodaldialog=null", "JavaScript");
Doc.parentwindow.execscript ("Window.close=null", "JavaScript");
}


Code written here has been submitted to the search, WebBrowser will also receive the submission of the demerit, the following we need to open a connection in the results of the experiment.
First look at the search results of the HTML source code

The code is as follows Copy Code
private void Webbrowser1_documentcompleted (object sender, WebBrowserDocumentCompletedEventArgs e)
{
HTMLDocument doc = this.webbrowser1.document;
if (doc.url.absoluteuri== "http://www.baidu.com/")
{
Doc.getelementbyid ("kw"). innertext = "Wong Yuri";
Doc.getelementbyid ("su"). InvokeMember ("click");
}
if (Doc.url.absoluteuri.contains ("WD"))//According to the URL of the
{
HtmlElement table = Doc.getelementbyid ("1");//According to the search results of the HTML table, find the first search results URL, where the simulation
var html = table.children[0].children[0].innerhtml;
var url = html.substring (Html.indexof ("href") + 6, Html.indexof ("target"));
This.webbrowser1.navigate (URL);
}
}

 

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.