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);
}
} |