Skip to Content
Google Hacks, 2nd Edition
book

Google Hacks, 2nd Edition

by Tara Calishain, Rael Dornfest
December 2004
Intermediate to advanced
480 pages
11h 38m
English
O'Reilly Media, Inc.
Content preview from Google Hacks, 2nd Edition

Get Random Results (on Purpose)

Surfing random pages can turn up some brilliant finds.

Why would any researcher worth her salt be interested in random pages? While surfing random pages isn’t what one might call a focused search, you’d be surprised at some of the brilliant finds that you’d never have come across otherwise. I’ve loved random page generators associated with search engines ever since discovering Random Yahoo! Link (http://random.yahoo.com/bin/ryl, although no longer working at the time of this writing). It made me think that creating such a thing to work with the Google API might prove interesting, useful even.

The Code

This code searches for a random number between 0 and 99999 (yes, you can search for 0 with Google) in addition to a modifier pulled from the @modifiers array. To generate the random page, you don’t, strictly speaking, need something from the modifer array. However, it helps make the page selection even more random.

With the combination of a number between 0 and 99999 and a modifier from the @modifiers array, Google will get a list of search results, and from that list you’ll get a “random” page. You could go higher with the numbers if you wanted, but I wasn’t sure that this hack would consistently find numbers higher than 99999. (Zip Codes are five digits, so I knew a five-digit search would find results more often than not.)

Save the code as a CGI script named goorandom.cgi. The only change you need to make is to replace insert key here with your Google ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Google Hacks, 3rd Edition

Google Hacks, 3rd Edition

Rael Dornfest, Paul Bausch, Tara Calishain
Google Hacks

Google Hacks

Tara Calishain, Rael Dornfest

Publisher Resources

ISBN: 0596008570