C # (Asp.net) captures content from other websites and captures useful information

Source: Internet
Author: User

1. class library to be referenced

 
Using system. Net; using system. IO; using system. Text; using system. Text. regularexpressions;

2. Key to obtaining webpage content from other websitesCode

 
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 webpage source code textbox1.text = reader. readtoend ();

 

3. Obtain the source code of other websites and use {Regular Expression} to select useful information.

Matchcollection titlematchs = RegEx. matches (reader. readtoend (), @ "comment </a> </P> </div> <Div class =" "body" "> ([\ 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

Welcome to join us!

Download sample source code

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.