1. Class libraries that need to be referenced
| 1234 |
usingSystem.Net;using System.IO;using System.Text;usingSystem.Text.RegularExpressions; |
2. Get the key code for the content of other Web pages
| 12345 |
WebRequest request = WebRequest.Create("http://目标网址.com/");WebResponse response = request.GetResponse();StreamReader reader = newStreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));//reader.ReadToEnd() 表示取得网页的源码TextBox1.Text = reader.ReadToEnd(); |
3. Get other Web pages after source code through {Regular expression} handsome select useful information
| 123456 |
matchcollection Titlematchs = regex.matches (reader. ReadToEnd (), @ "comments </a></p></div><div class=" "Body" > ([\s \s]*?) </div><div class= "" Share "" > " Regexoptions.ignorecase | Regexoptions.multiline); foreach (Match nextmatch in Titlematchs) { &NBSP;&NBSP;&NBSP;&NBSP; s + = "<br>" + nextmatch.groups[ 1]. Value; &NBSP;&NBSP;&NBSP;&NBSP; textbox1.text + = "\ n" + Nextmatch.groups[1]. Value; } |
Regexoptions.ignorecase: It is not case-sensitive, general Web site source code is insensitive, so cancel it.
Regexoptions.multiline: Indicates a handsome selection of multiple lines of content.
4. Done
No! Bad Impact! Forgive me.
Welcome to discuss with us!
Sample source Download
C # (ASP) fetches content from other sites and intercepts useful information