Programmatically get the number of indexed pages i

2019-04-16 00:15发布

As an SEO metric I'd like to programmatically get the number of by Google indexed pages.

(if I search "site:mydomain.com" I want the get number of pages found).

Is there any lib for this or do I need to parse a google request?

4条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-16 00:50

Here's something I put together that will work for a few queries per IP address per hour:

    public static Int32 GooglePages(string sourceDomain)
    {
        String googleSource
            = (new WebClient()).DownloadString(
                @"http://www.google.com/search?q=site%3A" + sourceDomain);

        return Convert.ToInt32(
            Regex.Match(googleSource, 
                @"about \<b\>([0-9,]*)\<\/b\> from ")
                .Groups[1].Value.Replace(",", ""));

    }

If you are going to use it often, or make many queries on a regular basis I would recommend using an officially sanctioned API.

查看更多
forever°为你锁心
3楼-- · 2019-04-16 00:57

Has your site been setup in Google Analytics? If so you can use the Google Analytics API to get such information.

If you're interested in how to implement this in asp.net refer to this question.

查看更多
Summer. ? 凉城
4楼-- · 2019-04-16 01:00

you should use Google Webmaster Tool API. First login in google webmaster with gmail account and familiar with the functionality then see following developer guide:
http://code.google.com/apis/webmastertools/docs/2.0/developers_guide.html

查看更多
女痞
5楼-- · 2019-04-16 01:05

There's probably a Google API you can use, rather than parsing the results of a search.

查看更多
登录 后发表回答