yitzle wrote:
Hi

Summary: Is there an easy method to search Google and get the top
result (title & URL)?

I'm trying to write a script that gets URLs based on a name. I figured
using Google would be the simplest method. I need to search a specific
site, and can construct a query so that the top result is often enough
the correct result.

However, Net::Google requires a SOAP API key, and Google's site says
they are no longer providing new keys. I thought I might be able to
use WWW::Mechanizer, but the HTML that Google returns is fairly ugly
and I haven't tried parsing that just yet.

Is there an easy method to search Google and get the top result (title & URL)?

I suggest you use Google's 'I'm Feeling Lucky' feature, which will
attempt to take you directly to the most appropriate Web site instead of
offering a list. The program below uses WWW::Mechanize to do this using
a query string of 'perl modules'. Note that the name of the 'I'm Feeling
Lucky' button is 'btnI', while the 'Google Search' button is named 'btnG'. The search query field is named 'q'.

I hope this helps.

Rob



use strict;
use warnings;

use WWW::Mechanize;

my $mech = WWW::Mechanize->new;

$mech->get('http://www.google.co.uk');
$mech->field('q', 'perl modules');
$mech->click('btnI');

print $mech->uri;

**OUTPUT**

http://www.cpan.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to