Using WebClient to capture Baidu's indexed data (C #)

Source: Internet
Author: User

Baidu crawlers of many ASP versions on the Internet are pasted with the Baidu indexing data acquisition method of Asp.net 2.0 and C. I hope you can correct it.

1 using system;
2 using system. Collections. Generic;
3 using system. text;
4 using system. net;
5 using system. Text. regularexpressions;
6 namespace Tool
7 {
8 public class seocount
9 {
10/*** // <summary> return to Baidu: number of entries included in a period
11 /// meaning of the strtimespan Parameter
12 // "1" select the number of entries to be queried in the last few days
13 // "1" query yesterday's records
14 // "7" query the records collected in the last week
15 // "30" query the records recorded in the last month
16 // "360" query the indexing status in the last year
17 // "0" query the total (ALL dates) records
18 /// </Summary>
19 /// <Param name = "strhostname"> </param>
20 /// <returns> </returns>
21 Public String baiducount (string strtimespan, string strhostname)
22 {
23 string uri = "http://www.baidu.com/s? Lm = "+ strtimespan +" & WD = site: "+ strhostname;
24 string html = new WebClient (). downloadstring (URI );
25 string pattern = @ "Baidu, find the relevant webpage [\ s] *? (? = Article, in use )";
26 // string number = new RegEx (@ "find related webpage ([\ D,] +)"). Match. Groups [1]. value;
27 string number1 = RegEx. Match (HTML, pattern, regexoptions. ignorecase). value;
28 string lastnumber = number1.replace ("Baidu, find the relevant webpage ","");
29 // if there are many articles to remove the approximate value, return a pure numeric string
30 if (lastnumber. Contains ("approx "))
31 {
32 lastnumber. Replace ("approx ","");
33}
34 // if neither of them returns 0
35 if (lastnumber = "")
36 {
37 lastnumber = "0 ";
38}
39 return lastnumber;
40
41}
42}
43}

 

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.