All,
I realise against gooogle ToC but I was trying to write a perl script that performs a google search and returns the number of hits (eg the 1 of about XXXX for search term). I should state I am perl newbie.
After reading etc this is what I have but it does not return any thing and I’m not sure why…can anyone give me some pointers.
use LWP::Simple;
my $ua = new LWP::UserAgent;
$ua->agent('Mozilla/5.0');
my $url=$ARGV[0];
my $req = HTTP::Request->new(GET => $url);
my $res = $ua->request($req);
$res->content;
print "all done \n";
while ($res ==~ /of about <b>([1234567890,]<\/b> +)/) {
print $res;
}
The line:
Has the following errors:
because…
/gglobal option, which would be uselessbecause…
[1234567890,]will only match one character, and is better written[0-9,]+. Note the plus sign at the end to allow multiple matches.==~should be=~$resshould probably be$res->content, like a’r stated in thecomment.
</b>tag, which I suppose isa typo?
Also, you print out the whole
$resobject, when you probably only want to print the number.More correct version: