D
demolitionz
I'm working on a project to try and write a program in perl which will
connect to google, search for a specified keyword and return the URLs
found. My problem is that I can only get the program to return the
first URL found, and despite spending a good few hours playing around
with it and searching the web for answers, I can't seem to solve the
problem. Here's the code I've written so far...
#!usr/bin/perl
use warnings;
use strict;
if ($ARGV[0] eq '') { print "Script called incorrectly.\nFormat:
google.pl keyword"; exit; }
use LWP::UserAgent;
my $browser = LWP::UserAgent->new;
my $response =
$browser->get("http://www.google.com/search?q=$ARGV[0]");
if ($response->is_success) {
if ($response->content =~ m{<font color=#008000>(.*?)</font>}i)
{
print "$1\n";
}
else { print "Could not connect"; }
}
exit;
Now I personally assumed the solution would have been as easy as
changing $1 to $2 to get the second URL, but it doesn't seem so. That
being the case I assume this script will need a total rework, but have
no idea where to even begin. Can anyone help?
connect to google, search for a specified keyword and return the URLs
found. My problem is that I can only get the program to return the
first URL found, and despite spending a good few hours playing around
with it and searching the web for answers, I can't seem to solve the
problem. Here's the code I've written so far...
#!usr/bin/perl
use warnings;
use strict;
if ($ARGV[0] eq '') { print "Script called incorrectly.\nFormat:
google.pl keyword"; exit; }
use LWP::UserAgent;
my $browser = LWP::UserAgent->new;
my $response =
$browser->get("http://www.google.com/search?q=$ARGV[0]");
if ($response->is_success) {
if ($response->content =~ m{<font color=#008000>(.*?)</font>}i)
{
print "$1\n";
}
else { print "Could not connect"; }
}
exit;
Now I personally assumed the solution would have been as easy as
changing $1 to $2 to get the second URL, but it doesn't seem so. That
being the case I assume this script will need a total rework, but have
no idea where to even begin. Can anyone help?