Google Hacks Free Open Book

Google Hacks

Previous Section Next Section

Hack 84 Finding the Largest Page

figs/moderate.giffigs/hack84.gif

We all know about Feeling Lucky with Google. But how about Feeling Large?

Google sorts your search result by PageRank. Certainly makes sense. Sometimes, however, you may have a substantially different focus in mind and want things ordered in some other manner. Recency is one that comes to mind. Size is another.

In the same manner as Google's "I'm Feeling Lucky" button redirects you to the search result with the highest PageRank, this hack sends you directly to the largest (in Kilobytes).

This hack works rather nicely in combination with repetition [Hack #7].

84.1 The Code

#!/usr/local/bin/perl
# goolarge.cgi
# A take-off on "I'm feeling lucky", redirects the browser to the largest
# (size in K) document found in the first n results.  n is set by number
# of loops x 10 results per.
# goolarge.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";

# Number of times to loop, retrieving 10 results at a time
my $loops = 10;

use strict;

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

# Display the query form
unless (param('query')) {
  print
    header(  ),
    start_html("GooLarge"),
    h1("GooLarge"),
    start_form(-method=>'GET'),
    'Query: ', textfield(-name=>'query'),
    '   ',
    submit(-name=>'submit', -value=>"I'm Feeling Large"),
    end_form(  ), p(  );
}

# Run the query
else {
  my $google_search  = SOAP::Lite->service("file:$google_wdsl");
  my($largest_size, $largest_url);

  for (my $offset = 0; $offset <= $loops*10; $offset += 10) {

    my $results = $google_search -> 
      doGoogleSearch(
        $google_key, param('query'), $offset, 
        10, "false", "",  "false", "", "latin1", "latin1"
      );

    @{$results->{'resultElements'}} or print p('No results'), last;

    # Keep track of the largest size and its associated URL
    foreach (@{$results->{'resultElements'}}) {
      substr($_->{cachedSize}, 0, -1) > $largest_size and
        ($largest_size, $largest_url) = 
        (substr($_->{cachedSize}, 0, -1), $_->{URL});
    }
  }

  # Redirect the browser to the largest result
  print redirect $largest_url;
}

84.2 Running the Hack

Call up the CGI script in your web browser. Enter a query and click the "I'm Feeling Large" button. You'll be transported directly to the largest page matching your query—within the first specified number of results, that is.

84.3 Usage Examples

Perhaps you're looking for bibliographic information for a famous person. You might find that a regular Google search doesn't net you with any more than a mention on a plethora of content-light web pages. Running the same query through this hack sometimes turns up pages with extensive bibliographies.

Maybe you're looking for information about a state. Try queries for the state name along with related information like motto, capitol, or state bird.

84.4 Hacking the Hack

This hack isn't so much hacked as tweaked. By changing the value assigned to the $loops variable in my $loops = 10;, you can alter the number of results the script checks before redirecting you to what it's found to be the largest. Remember, the maximum number of results is the number of loops multiplied by 10 results per loop. The default of 10 considers the top 100 results. A $loops value of 5 would consider only the top 50; 20, the top 200; and so forth.

    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