#!/usr/bin/perl
#######################
# By: Ventz Petkov    #
# Date: 6-22-05       #
# Google Search       #
#######################
if (@ARGV != 1) {
    print "\t\tUsage: ./google.pl query\n";
    print "\t\tEx: ./google.pl rss\n"; exit();
}

use warnings;
use strict;

use WWW::Mechanize;

my $mech = WWW::Mechanize->new();
my $url = 'http://google.com';

$mech->agent_alias( 'Mac Safari' );
$mech->get( $url );


$mech->submit_form  (
    form_name => 'f',
    fields    => { q  => $ARGV[0], }, 
    button    => 'btnG'
);

foreach ($mech->links) {
    my $text = $_->text;
    my $link = $_->url;

    # Get rid of First Page Add, Cache, Similar Pages, Other Pages
    next if !($link =~ /^http:\/\//);
    next if ($link =~ /http:\/\/www.google.com/);
    next if ($link =~ /http:\/\/images.google.com/);
    next if ($link =~ /http:\/\/groups.google.com/);
    next if ($link =~ /http:\/\/news.google.com/);
    next if ($link =~ /http:\/\/froogle.google.com/);
    next if ($link =~ /http:\/\/local.google.com/);
    next if ($link =~ /http:\/\/translate.google.com/);
    next if ($link =~ /pagead\/iclk\?adurl/);
    next if ($link =~ /search\?q=/);
    next if ($link =~ /\/search\?hl=en&lr=&q=related:/);
    
    # Print results - list of Name/URL
    print "$text\n";
    print "\t$link\n\n";
}
