Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Show number of Google results for a set of sites.
#!/usr/bin/env sh
# $ ./google-results.sh
# Fri Sep 30 15:43:01 EDT 2011|http://www.google.com/search?q=site:amazon.com|360,000,000
# Fri Sep 30 15:43:06 EDT 2011|http://www.google.com/search?q=site:apple.com|46,500,000
# Fri Sep 30 15:43:11 EDT 2011|http://www.google.com/search?q=site:facebook.com|2,600,000,000
# Fri Sep 30 15:43:16 EDT 2011|http://www.google.com/search?q=site:google.com|281,000,000
URLS=(
"http://www.google.com/search?q=site:amazon.com"
"http://www.google.com/search?q=site:apple.com"
"http://www.google.com/search?q=site:facebook.com"
"http://www.google.com/search?q=site:google.com"
)
USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1"
hash curl 2>&- || { echo "Requires curl. Aborting."; exit 1; }
hash date 2>&- || { echo "Requires date. Aborting."; exit 1; }
hash tr 2>&- || { echo "Requires tr. Aborting."; exit 1; }
hash perl 2>&- || { echo "Requires perl. Aborting."; exit 1; }
for ((i=0; i < ${#URLS[@]}; i++))
do
if [ $i -ne 0 ]; then
sleep 5 # So we don't look so robotic!
fi
DATE=`date`
URL=${URLS[i]}
SIZE=`curl -s --user-agent "$USER_AGENT" $URL 2>&1 | tr -d "\r \n" | perl -ne '$_ =~ m/About([0-9|,]+)results/; print "$1\n";'`
echo "$DATE|$URL|$SIZE"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment