Monday, May 6, 2013

Google's Selfish Move to keep I'm feeling lucky all to itself...

As you probably have heard, Google "tried" to pull its "I'm feeling lucky" button (hereafter referred to as 'IFLB') from it's main page a while back because they thought they were losing millions of $$$ off of it.  Truth be told, the damn google ads are on so many pages these days I cant see how skipping the search page has any bearing except diminishing use and possibly even reducing sales but thats not the point of this post. The point is, when the IFLB came back, it was not the same IFLB it was before. They selfishly (and sneakily) made it so other sites and people who wanted to use this feature, were severely limited in doing so. You know what I'm talking about, sending a link like this :
"http://www.google.com/search?btnI=1&q=test"
Now, that above, works fine.. but if you want a query thats more than 3 words you are shit out of luck, you get the index results page as if btnI=1 was not included. This is due to some sneaky javascript you can see by viewing the pages source, not only is there the usual btnI=1 passed, but some javascript function is called along with that submit to tell google to create a temporary link (which you would normally never see unless you use lynx like I do) and then which in turn follows to the first returned page.  This is so funny because to do THAT is a hell of alot more code than just to do what it USED to do. So they cant defend saying that people are using too many resources, because they are voluntarily creating a bigger use of resources by adding this stuff. Case in point: my solution to the problem: at least, for linux users (and windows users who use the linux ported tools such as cygwin or native ports). You CAN get the old IFLB functionailty back with a simple bash script like this:

#!/bin/bash
# the script assumes that the command line consists of just search terms
# below $LINK_COUNT is a number 10-100
# $TERMS is your search terms (multiple+words+like+this)
# $LINKS is the list of $LINK_COUNT links returned by the initial screening
# $BROWSER is the web browser command (+args maybe) for final viewing
# $RESULTS_TO_OPEN is the number of links to pass to $BROWSER's 
# command line

BROWSER=/usr/bin/X11/firefox
LINK_COUNT=10
# begin, actual commands
# command 1
TERMS=`echo $*|sed 'y/ /+/'`
# command 2
LINKS=`lynx -dump google.com/search?q=$TERMS\&num=$LINK_COUNT | grep -P \

--color=never "\- [0-9]+k \-" | grep -P --only-matching --color=never "^[ ]*[^ ]*" | \
grep -P --$`
# command 3
$BROWSER `echo $LINKS | grep ".*" -m $RESULTS_TO_OPEN --color=never` > /dev/null 2>&1 &
You see, only 3 ****ing commands here! it could even be put into one command if one wants to be overly ostentatious (which i cant stand linux users who are like that). I suppose you could argue that some of the commands actually call more than one, like command 2 actually calls lynx, grep, grep(again), and grep (AGAIN) which is actually 4 not 1. But for the purposes of the example, whatever.  So my intent here is to goose google from behind with this and piss in their face. Whatever works right? Why did I not use GET and AWK?? because unlike the html source, the basic text that is shown in reults pages do not change much in structure, the source could be completely redesigned tomarrow and break things badly if I were to go the route of parsing the source from the initial dump. Yes i know its bad form because one assumes one has lynx installed which usually isnt the case in default distributions but if you dont have it, its just one apt-get, yum, rpm, wget, etc away right?


1 comment: