C # (ASP) fetches content from other sites and intercepts useful information

Source: Internet
Author: User

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

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.