I came across a line of hacking books today which proved fun. This hack for Google led to this modified script which runs the query live instead of pulling it from a saved results file:
#!/usr/bin/perl
# google_search.pl # Google Web Search Results exported to CSV suitable
# for import into Excel
# Usage: perl google_search.pl term1 term2 termN > results.csv
use LWP;
my $browser = LWP::UserAgent->new;
# Google doesn't like non-browser-based access:
$browser->agent('Mozilla/4.76 [en] (Win98; U)');
my $qstring = join("+", @ARGV);
my $url = 'http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=' . $qstring . '&btnG=Google+Search';
my $response = $browser->get($url);
print qq{"title","url","size","domain suffix"\n};
my($results) = (join '', $response->content) =~ m!<div>(.*?)</div>!mis;
while ( $results =~ m!<a href="?(.+?)"?>(.+?)</a>.+?\s+-\s+(\d+k)?!mgis ) {
my($url,$title, $size) = ($1||'',$2||'',$3||'');
my($suffix) = $url =~ m!\.(\w+)/!;
$title =~ s!"!""!g; # double escape " marks
$title =~ s!<.+?>!!g; # drop all HTML tags
print qq{"$title","$url","$size","$suffix"\n};
}
Posted by greg at September 10, 2003 03:05 PM
| TrackBack
What do i doe whit script war due i put it ?
i am new to this
The script can be put anywhere ... on your desktop, in a folder, etc. It's a perl program, so you should have some experience running perl before trying to use this. Most folks are on windows, so use ActivePerl as their perl executable: www.activestate.com.
How do you stop the script from closing after you open the script? I can't seem to get it to stop from closing...
The script will always close at some point after it is opened ... it's designed that way. It will loop over the results until it's done and then end.
To get it to do something after the loop, edit the script after the while loop ends. Feel free to make it do what you'd like after that.