Here, a textbox is used to receive the input URL, which can capture all the hyperlinks on the webpage. Code As follows:String HTTP = txthttp. text. tostring (); // target webpage URL </P> <p> system. net. webrequest request = system. net. webrequest. create (HTTP); <br/> system. io. streamreader sr = new system. io. streamreader (request. getresponse (). getresponsestream (), system. text. encoding. getencoding ("gb2312"); <br/> arraylist list = new arraylist (); <br/> If (SR! = NULL) <br/>{< br/> string html = sr. readtoend (); <br/> // The Key is regular expressions. Find the source code of the target webpage, summarize the regular expression <br/> // search robots dispatched by various search engines Capture web snapshots in this way <br/> system. text. regularexpressions. matchcollection MC = system. text. regularexpressions. regEx. matches (HTML, @ "<A/S + href/S * =/S * [" "| ']? (? <URI> [^ "" '] *) ["" |']? [^ <>] *>/S * (<[^ <>] +> )*(? <Title> [^ <>] *) (<[^ <>] +>) */S * </a> "); <br/> for (INT I = 0; I <MC. count; I ++) <br/>{< br/> list. add (MC [I]. value. tostring (); // Add the matched items to the arraylist <br/>}< br/> foreach (string STR in List) <br/> {<br/> response. write (STR + "<br/>"); <br/>}< br/> Sr. close (); <br/>}
I personally think the most important thing here is regular expressions. Different regular expressions can capture different contents.