usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingmshtml;usingSystem.Collections;usingSystem.Threading;namespacetraverse Baidu Web page { Public Delegate voidbaidu111 (); Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidForm1_Load (Objectsender, EventArgs e) {Listview1.gridlines=true; } thread thread; voidBaidu () {baidu111 (); } voidbaidu111 () {if(webbrowser1.invokerequired) {baidu111 Dr=Newbaidu111 (baidu111); This. Invoke (DR); } Else { stringURL ="http://www.baidu.com/s?wd="+TextBox1.Text; WebBrowser1.Navigate (URL. Trim ()); } } //Click Stop Private voidButton2_Click (Objectsender, EventArgs e) { } Private voidButton1_Click (Objectsender, EventArgs e) { //System.Diagnostics.Process.Start ("http://www.baidu.com"); //webbrowser1.navigate ("http://www.baidu.com/");Thread =NewThread (NewThreadStart (Baidu)); Thread. IsBackground=true; Thread. Start (); Baidu (); } inti =0; Public voidBianli () {IHTMLDocument2 doc= WebBrowser1.Document.DomDocument asIHTMLDocument2; foreach(IHTMLElement eleinchdoc.all) {if(Ele.innertext = ="Next page >") {Ele.click (); I++; if(i==3) { Break; } } } } /// <summary> ///To interpret whether the Web page is loading completed/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidWebbrowser1_documentcompleted (Objectsender, WebBrowserDocumentCompletedEventArgs e) { if(i==3) { return; } if(E.url = =webBrowser1.Document.Url) {Bianliwangye (); } } /// <summary> ///enumeration gets all URLs of Baidu search page/// </summary> /// ArrayList All=NewArrayList (); stringA1; Public voidBianliwangye () {IHTMLDocument2 document= (IHTMLDocument2) webBrowser1.Document.DomDocument;//Get Source codeIHTMLElementCollection HC = (ihtmlelementcollection) document.all;//Get all Tags//MessageBox.Show (HC. ToString ()); foreach(IHTMLElement HinchHc//Traverse Tags { if(H.classname = ="g"|| H.classname = ="C-showurl")//classname interpretation by label { stringA = h.innerhtml;//get label text content if(A.contains (" in")) { intb = A.indexof (" in"); A1= A.substring (0, b);//Intercept URLsMessageBox.Show (A1); All. ADD (A1); }}} Bianli ();//when enumerating to the last URL of the current page, simulate click to go to the next page } Private voidButton3_Click (Objectsender, EventArgs e) {LISTVIEW1.COLUMNS.ADD ("numbering"); LISTVIEW1.COLUMNS.ADD ("get to the URL", -); for(inti =0; I < All. Count; i++) {ListView1.Items.Add ((i+1). ToString ()); Listview1.items[i]. SubItems.Add (All[i]. ToString ()); } } }}
C # language Input keywords, crawl all the URLs you want