Asp.net getting started using regular expressions to capture web page information

Source: Internet
Author: User

Today, I have nothing to worry about using regular expressions. I used regular expressions for verification. I used them for the first time to capture webpages,

I grabbed the list of Recommendation articles on several pages on the blog homepage ....

The code is very simple and I will not explain it. It must be not rigorous. I am familiar with the following regular expressions and methods used to capture webpage content...

Using System;
Using System. Web;
Using System. Web. UI;
Using System. Text. RegularExpressions;
Using System. Net;
Using System. IO;
Public partial class test: Page
{
Public int g = 0;
Public string dfdf = "";
Void Page_Load (object sender, System. EventArgs e)
{
For (int I = 2; I <10; I ++)
{
WebRequest rque = WebRequest. Create ("http://www.cnblogs.com/p" + I. ToString ());
WebResponse utxt = rque. GetResponse ();
Stream str = utxt. GetResponseStream ();
StreamReader sread = new StreamReader (str, System. Text. Encoding. UTF8 );

String pram = @ "MatchCollection m = Regex. Matches (sread. ReadToEnd (), pram );
Foreach (Match MS in m)
{
G + = 1;
Dfdf = dfdf + ms. groups [1]. value. toString () + ms. groups [2]. value. toString () + "<br/> ";
}
}

Response. Write ("Total number of records:" + g. ToString () + "<br/>" + dfdf );
}
}

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.