Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

c# google page indexed listing script

This code shows how many pages are indexed by google for a given site

using System;

using System.Collections.Generic;

using System.Text;

using System.Net;

namespace GoogleSearchCounts

{

public enum CountTypes

{

SiteCounts,

LinkCounts

}

public class Counts

{

private Counts() { }

//Usage: int val = GoogleSearchCounts.Counts.GetCounts(url, CountTypes.LinkCounts);

public static int GetCounts(string siteUrl, CountTypes countType)

{

int retval=0;

try

{

string searchUrl2 = String.Empty;

string searchUrl = "http://www.google.com/search?hl=en&q=";

searchUrl2 =(countType == CountTypes.LinkCounts)?"link%3A":"site%3A";

string sFullSearchUrl = string.Concat(searchUrl, searchUrl2, siteUrl);

WebClient wc = new WebClient();

byte[] b = wc.DownloadData(sFullSearchUrl);

wc.Dispose();

string strContent = System.Text.Encoding.UTF8.GetString(b);

int startPos = strContent.IndexOf("of about ");

strContent = strContent.Substring(startPos);

int endPos = strContent.IndexOf("
");

strContent = strContent.Substring(12, endPos-12);

strContent = strContent.Replace(",", "");

retval = int.Parse(strContent);

}

catch (Exception ex)

{

System.Diagnostics.Debug.WriteLine(ex.Message + ex.StackTrace);

}

return retval;

}

}

}

Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy