Asp.net crawls content from other websites and captures useful information,1. class library to be referenced
1 using system. net;
2 using system. IO;
3 using system. text;
4 using system. Text. regularexpressions;
2. Key to obtaining webpage content from other websitesCode
1 webrequest request = webrequest. Create ("/");
2 webresponse response = request. getresponse ();
3 streamreader reader = new streamreader (response. getresponsestream (), encoding. getencoding ("gb2312 "));
4 // reader. readtoend () indicates obtaining the source code of the webpage
5 textbox1.text = reader. readtoend ();
3. Obtain the source code of other websites and use {Regular Expression} to select useful information.
1 matchcollection titlematchs = RegEx. matches (reader. readtoend (), @ "comment </a> </P> </div> <Div class =" "body" "> ([\ s] *?) </Div> <Div class = "share" ">", regexoptions. ignorecase | regexoptions. multiline );
2 foreach (match nextmatch in titlematchs)
3 {
4 S + = "<br>" + nextmatch. Groups [1]. value;
5 textbox1.text + = "\ n" + nextmatch. Groups [1]. value;
6}
Regexoptions. ignorecase: indicates that the source code is case insensitive.
Regexoptions. multiline: indicates the selection of multi-line content.