Google Hacks Free Open Book

Google Hacks

Previous Section Next Section

Hack 69 Feeling Really Lucky

figs/expert.giffigs/hack69.gif

Take the domain in which the first result of a query appears, and do more searching within that domain.

Does Google make you feel lucky Section 1.4? How lucky? Sometimes as lucky as the top result is, more results from the same domain are just as much so.

This hack performs two Google queries. The domain of the top result of the first search is saved. Then the second query is run, searching only the saved domain for results.

Take, for example, Grace Hopper, famous both as a computer programmer and as the person who coined the term "computer bug." If you were to run a search result with "Grace Hopper" as the primary search and overlay a search for COBOL on the domain of the first result returned, you'd find three pages for the Grace Hopper Conference 2000:

Grace Hopper Conference 2000 - Biography
http://www.sdsc.edu/hopper/GHC_INFO/hopper.html
... The Murrays were a family with a long military
tradition;
Grace Hopper's ... language instructions led ultimately
to the
development of the business language COBOL ...
Note:
http://www.sdsc.edu/~woodka/intro.html
... publication, please contact me by email at:
woodka@sdsc.edu.
... and were important in its history, like Admiral
Grace Hopper,
the inventor of the COBOL ...
Grace Hopper
http://www.sdsc.edu/~woodka/hopper.html
... Hopper was a programmer on the world's first
large-scale
digital computer, Mark ... the first computer language
compiler,
and she worked on the development of COBOL ...

You could also do a primary search for a person ("Stan Laurel") and a secondary search for another person ("Oliver Hardy"). Or search for a person, followed by their corporate affiliation.

Don't try doing a link: search with this hack. The link: special syntax doesn't work with any other special syntaxes, and this hack relies upon inurl:.

69.1 The Code

#!/usr/local/bin/perl
# goolucky.cgi
# gleans the domain from the first (read: top) result returned, allows
# you to overlay another query, and returns the results, and so on...
# goolucky.cgi is called as a CGI with form input

# Your Google API developer's key
my $google_key='insert key here';

# Location of the GoogleSearch WSDL file
my $google_wdsl = "./GoogleSearch.wsdl";

use strict;

use SOAP::Lite;
use CGI qw/:standard/;

# Create a new SOAP instance
my $google_search = SOAP::Lite->service("file:$google_wdsl");

# If this is the second time around, glean the domain 
my $query_domain = param('domain') ? "inurl:" . param('domain') : '';
my $results = $google_search ->
  doGoogleSearch(
    $google_key, param('query') . " $query_domain", 0, 10,
    "false", "", "false", "", "latin1", "latin1"
  );

# Set domain to the results of the previous query
param('domain', $results->{'resultElements'}->[0]->{'URL'});
param('domain', param('domain') =~ m#://(.*?)/#);

print
  header(  ),
  start_html("I'm Feeling VERY Lucky"),
  h1("I'm Feeling VERY Lucky"),
  start_form(  ),
  'Query: ', textfield(-name=>'query',
  -default=>'"Grace Hopper"'),
  '   ',
  'Domain: ', textfield(-name=>'domain'),
  '   ',
  submit(-name=>'submit', -value=>'Search'),
  p(  ),
  'Results:';

foreach (@{$results->{'resultElements'}}) {
  print p(
    b($_->{title}), br(  ),
    a({href=>$_->{URL}}, $_->{URL}), br(  ),
    i($_->{snippet})
  );
}

print
  end_form(  ),
  end_html(  );

69.2 Hacking the Hack

You can also run this hack so it only uses one query. For example, you do a search with Query A. The search grabs the domain from the first result. Then you run another search, again using Query A, but restricting your results to the domain that was grabbed in the first search. This is handy when you're trying to get information on one set of keywords, instead of trying to link two different concepts. Figure 6-10 illustrates the I'm Feeling Lucky search.

Figure 6-10. I'm Feeling VERY Lucky search
figs/gooH_0610.gif
    Previous Section Next Section


         Main Menu
    Main Page
    Table of content
    Copyright
    Dedication
    Credits
    Foreword
    Preface
    Chapter 1. Searching Google
    Chapter 2. Google Special Services and Collections
    Chapter 3. Third-Party Google Services
    Chapter 4. Non-API Google Applications
    Chapter 5. Introducing the Google Web API
    Chapter 6. Google Web API Applications
    6.1 Hacks #60-85
    6.2 The Ingenuity of Millions
    6.3 Learning to Code
    6.4 What You'll Find Here
    6.5 Finding More Google API Applications
    6.6 The Possibilities Aren't Endless, but They're Expanding
    Hack 60 Date-Range Searching with a Client-Side Application
    Hack 61 Adding a Little Google to Your Word
    Hack 62 Permuting a Query
    Hack 63 Tracking Result Counts over Time
    Hack 64 Visualizing Google Results
    Hack 65 Meandering Your Google Neighborhood
    Hack 66 Running a Google Popularity Contest
    Hack 67 Building a Google Box
    Hack 68 Capturing a Moment in Time
    Hack 69 Feeling Really Lucky
    Hack 70 Gleaning Phonebook Stats
    Hack 71 Performing Proximity Searches
    Hack 72 Blending the Google and Amazon Web Services
    Hack 73 Getting Random Results (On Purpose)
    Hack 74 Restricting Searches to Top-Level Results
    Hack 75 Searching for Special Characters
    Hack 76 Digging Deeper into Sites
    Hack 77 Summarizing Results by Domain
    Hack 78 Scraping Yahoo! Buzz for a Google Search
    Hack 79 Measuring Google Mindshare
    Hack 80 Comparing Google Results with Those of Other Search Engines
    Hack 81 SafeSearch Certifying URLs
    Hack 82 Syndicating Google Search Results
    Hack 83 Searching Google Topics
    Hack 84 Finding the Largest Page
    Hack 85 Instant Messaging Google
    Chapter 7. Google Pranks and Games
    Chapter 8. The Webmaster Side of Google
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele