1. class library to be referenced
Using system. Net; using system. IO; using system. Text; using system. Text. regularexpressions;
2. Key to obtaining webpage content from other websitesCode
Webrequest request = webrequest. create ("http: // target URL. COM/"); webresponse response = request. getresponse (); streamreader reader = new streamreader (response. getresponsestream (), encoding. getencoding ("gb2312"); // reader. readtoend () indicates obtaining the webpage source code textbox1.text = reader. readtoend ();
3. Obtain the source code of other websites and use {Regular Expression} to select useful information.
Matchcollection titlematchs = RegEx. matches (reader. readtoend (), @ "comment </a> </P> </div> <Div class =" "body" "> ([\ s] *?) </Div> <Div class = "" share ">", regexoptions. ignorecase | regexoptions. multiline); foreach (match nextmatch in titlematchs) {S + = "<br>" + nextmatch. groups [1]. value; textbox1.text + = "\ n" + nextmatch. groups [1]. value ;}
Regexoptions. ignorecase: indicates that the source code is case insensitive.
Regexoptions. multiline: indicates the selection of multi-line content.
4. Success
No! Poor impact! Forgive me
Welcome to join us!
Download sample source code