YuviSense: Codin Kid

Yuvi, a 17 year old wannabe geek from India.
  • rss
  • Blog
  • Photography
  • Indians on Twitter
  • About Me
  • Contact

Code: Number of Times a Term occurs in Google

October 28, 2007 | 5:49 pm

Just some simple code to grab the number of times a term occurs on the web, according to Google. I found myself using this, and figured this’d be useful for others as well. And, I did this in C# rather than my usual darlin VB9 just for a change.


                Regex r = new Regex(@”\<\/b\> of about \<b\>(?<count>.*)\<\/b\> for”);
                WebClient wc = new WebClient();
                string url = “http://google.com/search?q=” + Uri.EscapeUriString(q);
                string page = wc.DownloadString(url);
                Match m = r.Match(page);
                if (m.Success) { Console.WriteLine(m.Groups[“count”].Value); }
                else { Console.WriteLine(0); } //No matches found,

Just put q into whatever term you want it to be, and you’re ready to go. Since the Google SOAP API was killed, scrapping is perhaps the fastest way to get data out of Google, and they have some of the most uglily structured code lying around. If I had first tried scrapping against Google instead of Wordpress when I started, I would’ve very certainly given up. It’s that bad.

And, btw, the last else is there to support searches for which there are no results. Most of the rest is self explanatory.

Categories
Tech
Comments rss
Comments rss
Trackback
Trackback

« Back from Vacation! Sumaya Silhoutte »

10 responses

The Google SOAP API is still available. The guy who

Prolific Programmer | October 29, 2007 | 2:29 am

The Google SOAP API is still available. The guy who wrote it left Google and therefore it won’t be maintained anymore.

@Profilic Programmer: Yep, it's still available. But, no new API

yuvipanda | October 29, 2007 | 2:31 am

@Profilic Programmer: Yep, it’s still available. But, no new API keys will be issued, which basically means it’s dead…

Now, I’d love to see the Perl one-liner that does this :)

^ or the javascript ones 8 ) especially with the

Bhasker V K | October 29, 2007 | 10:07 am

^ or the javascript ones 8 ) especially with the versatility that you get with firebug’s console.

Keep Clicking,
Bhasker V Kode

The Javascript API isn't an API: It's just a library.

yuvipanda | October 29, 2007 | 12:30 pm

The Javascript API isn’t an API: It’s just a library. I can’t use it from VB9 or C#, for example. For all intents and purposes, there’s no Google Search API right now folks.

@YuviPanda any API is no more than a library.

Prolific Programmer | October 29, 2007 | 12:37 pm

@YuviPanda
any API is no more than a library.

nah, with an API (a real, Web API), my chosen

yuvipanda | October 29, 2007 | 12:42 pm

nah, with an API (a real, Web API), my chosen language doesn’t matter at all. I could just as well use LOLCODE for it. But with a Library, you’re tied to the language which the library supports. Different, no?

You need protocol support in LOLCODE for whatever web API

Prolific Programmer | October 29, 2007 | 3:03 pm

You need protocol support in LOLCODE for whatever web API uses, i.e. HTTP requests, which are far easier to do in some languages than others. See my blog for some ruby code to manipulate twitter into doing what I want, for example of a language that makes web manipulation easy.

To a certain extent, you’re spot on that you are tied to the langauge which the library supports. However, every language I know of has a C API, at some level. Therefore one can design wrappers around a given C library in python, perl, ruby, Java, etc.

Granted, I don’t know every language in existence and I don’t know .Net at all

Yes, but have you looked at the Google Search Javascript

yuvipanda | October 29, 2007 | 3:10 pm

Yes, but have you looked at the Google Search Javascript “API”? It’s a mass of obfuscated javascript, more like a traditional obfuscated compiled dll. You have pretty much zero chance of using it from anything else, unless you do something like embed IE (or Gecko) into your code (via C) and access it via that. This involves multiple levels of cross-language calls, which are as easy as biting off pizza with your mouth closed.

Bottom line: The Google Search “API” is tied to just Javascript, and so is just a library, not an API. Agreed?

Hey Yuvi, I guess you are aware of the Live Search

Ahmad | October 30, 2007 | 5:19 pm

Hey Yuvi,

I guess you are aware of the Live Search 2.0 Wave and yea they do provide a sexy Search API. Stay away from Evil :-)

http://msdn2.microsoft.com/en-us/library/bb266180.aspx

Wow, thanks for pointin THAT out Ahmed :) Sounds cool,

yuvipanda | October 30, 2007 | 5:22 pm

Wow, thanks for pointin THAT out Ahmed :) Sounds cool, will check that out :)

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Contact Me

Email: yuvipanda@gmail.com
IM: yuvipanda@msn.com
GTalk: yuvipanda

My Photos


View my Flickr Page

My Badge


IndiBlogger - Where Indian Blogs Meet

Archives

  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox