ASP.net of C an implementation code that extracts content from other websites and intercepts useful information

  • 2020-05-12 02:29:07
  • OfStack

1. Class libraries to reference
 
using System.Net; 
using System.IO; 
using System.Text; 
using System.Text.RegularExpressions; 

2. Get the key codes of the web content of other websites
 
WebRequest request = WebRequest.Create("http:// The target site .com/"); 
WebResponse response = request.GetResponse(); 
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); 
//reader.ReadToEnd()  Means to get the source of a web page  
TextBox1.Text = reader.ReadToEnd(); 

3. Select useful information by {regular expression} after obtaining the source code of other web pages
 
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: means case-insensitive, 1 common website source case sensitive so cancel it.

RegexOptions.Multiline: means to select multiple lines of content.
4. You're done
No more pictures! Bad influence! Forgive me forgive me
The code is packaged and downloaded

Related articles: