ASP.net (C #) captures content from other websites and captures the implementation code of useful information.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.