O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



Google search scraper bookmarklet revisited.
Scrapes the search links from a Google search results page and produces an HTML table with columns <item no> <title> and <link> in a popup window.

Contributed by:
David Crossman
[03/29/04 | Discuss (2) | Link to this hack]

A prior version of this hack, Google Scraper, produced a list of comma-separated values. This version instead outputs an HTML table.

This output can be directly pasted into MS-Excel:
  select the contents of the popup window for copying (ctrl-A,ctrl-C),
  right-click on the target worksheet cell,
  select "Paste special -> HTML".
That's all there is to it.

To implement this hack in your browser, drag this link to your browser toolbar: gglTbl
The bookmarklet consists of the following JavaScript code:

javascript:
t = '</td><td nowrap>';
z = document.getElementsByTagName('p');
s = location.href.match(/start=(\d+)/)?RegExp.$1:0;
x = '<table>';
for (y = 0; y < z.length; y++)
	if(z[y].className == 'g') {
		m = z[y].innerHTML.match(/<a .*?<\/a>/igm);
		for(w = 0; w < m.length; w++)
			if(!!(v = m[w].match(/href="?([^ ">]+)[^>]*>(.+?)<\/a>/i)))
				x += '<tr><td>' + s + t + v[2].replace(/<br>/ig,' ').replace(/<[^>]+./g,'')
				+ t + (/^\//.test(v[1])?'http://'+location.host:'')+v[1]+'</td></tr>';
		s++;
	}
with((window.open('')).document) {
	write(x, '</table>');
	close();
}
You might be asked for confirmation, because JavaScript is not a standard protocol.
Because bookmarklets are limited in size, this hack does not specify the character encoding of the popup window;
it will open with your browser's default encoding. Change as necessary.
Popup blockers may block this hack.
Works internationally, at, e.g., google.co.uk, google.fr, google.de, ...

Sample output:

0oreilly.com -- Online Catalog: Google Hackshttp://www.oreilly.com/catalog/googlehks/
0Cachedhttp://216.239.39.104/search?q=cache:WF-U3VV6vQMJ:www.oreilly.com/catalog/googlehks/+google+hacks&hl=en&ie=UTF-8
0Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:www.oreilly.com/catalog/googlehks/
1Google Hackshttp://douweosinga.com/projects/googlehacks
1Cachedhttp://216.239.39.104/search?q=cache:Hj_ND84YoIkJ:douweosinga.com/projects/googlehacks+google+hacks&hl=en&ie=UTF-8
1Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:douweosinga.com/projects/googlehacks
2Amazon.com: Books: Google Hacks: 100 Industrial-Strength Tips & ...http://www.amazon.com/exec/obidos/tg/detail/-/0596004478?v=glance
2Cachedhttp://216.239.39.104/search?q=cache:yCA_A4LvJkoJ:www.amazon.com/exec/obidos/tg/detail/-/0596004478%3Fv%3Dglance+google+hacks&hl=en&ie=UTF-8
2Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:www.amazon.com/exec/obidos/tg/detail/-/0596004478%3Fv%3Dglance
3Moving to the new page....http://www.buzztoolbox.com/google/
3Cachedhttp://216.239.39.104/search?q=cache:Z9sGM1P3qHMJ:www.buzztoolbox.com/google/+google+hacks&hl=en&ie=UTF-8
3Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:www.buzztoolbox.com/google/
4Why Google Hacks is a Bestsellerhttp://searchenginewatch.com/searchday/article.php/2209681
4Cachedhttp://216.239.39.104/search?q=cache:WW2CNroxrBsJ:searchenginewatch.com/searchday/article.php/2209681+google+hacks&hl=en&ie=UTF-8
4Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:searchenginewatch.com/searchday/article.php/2209681
5O'Reilly Japan -- Catalog -- Google Hackshttp://www.oreilly.co.jp/BOOK/googlehks/
5Cachedhttp://216.239.39.104/search?q=cache:3cg0-puG13MJ:www.oreilly.co.jp/BOOK/googlehks/+google+hacks&hl=en&ie=UTF-8
5Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:www.oreilly.co.jp/BOOK/googlehks/
6O'Reilly Network: Google [Mar. 14, 2003]http://hacks.oreilly.com/pub/ht/2
6Cachedhttp://216.239.39.104/search?q=cache:FbXt7aMV5PcJ:hacks.oreilly.com/pub/ht/2+google+hacks&hl=en&ie=UTF-8
6Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:hacks.oreilly.com/pub/ht/2
7google-hacks.pagina.nlhttp://google-hacks.pagina.nl/
7Cachedhttp://216.239.39.104/search?q=cache:JXpkCw0GcPsJ:google-hacks.pagina.nl/+google+hacks&hl=en&ie=UTF-8
7Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:google-hacks.pagina.nl/
8Slashdot | Google Hackshttp://books.slashdot.org/books/03/03/11/1448253.shtml?tid=95
8Cachedhttp://216.239.39.104/search?q=cache:-HtKtfGzAEIJ:books.slashdot.org/books/03/03/11/1448253.shtml%3Ftid%3D95+google+hacks&hl=en&ie=UTF-8
8Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:books.slashdot.org/books/03/03/11/1448253.shtml%3Ftid%3D95
9Google Hacks (Tara Calishain, Rael Dornfest)http://dannyreviews.com/h/Google_Hacks.html
9Cachedhttp://216.239.39.104/search?q=cache:UQc_kcBMfDsJ:dannyreviews.com/h/Google_Hacks.html+google+hacks&hl=en&ie=UTF-8
9Similar pageshttp://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&c2coff=1&q=related:dannyreviews.com/h/Google_Hacks.html

Requirements: JavaScript supporting level 1 DOM (Gecko, IE5+)
Verified in IE6.0 (6.0.2800.1106;SP1) and NS7.0 (rv:1.0.1 Gecko/20020823).


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.