Programmatically get the number of indexed pages in Google?

假装没事ソ 提交于 2019-12-06 13:26:40

问题


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?


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/1833926/programmatically-get-the-number-of-indexed-pages-in-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!