1. class library to be referenced
Copy codeThe Code is as follows: using System. Net;
Using System. IO;
Using System. Text;
Using System. Text. RegularExpressions;
2. Obtain the key code of the webpage content of other websitesCopy codeThe Code is as follows: 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 source code of the webpage.
TextBox1.Text = reader. ReadToEnd ();
3. Obtain the source code of other websites and use {Regular Expression} to select useful information.Copy codeThe Code is as follows: MatchCollection TitleMatchs = Regex. matches (reader. readToEnd (), @ "comment </a> </p> </div> <div class =" "body" "> ([\ s \ 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
Package and download the code in this article