Dear Monks, I have been working on a program that returns the link count from google and I have come across a problem when using simple_request which is part of HTTP::Request. I found an example here (offsite) and used some of the code. Here is my code:
#!/usr/local/bin/perl -w use strict; use URI; use LWP; foreach my $word (@ARGV) { next unless length $word; # sanity-check my ($content, $status, $is_success) = &do_GET($word); if (!$is_success) { print "Sorry, failed: $status\n"; } elsif ($content =~ /\sof\sabout\s<b>([\d,]+)<\/b>/) { print "$word: $1 matches\n"; } else { print "$word: page not processable\n"; } sleep 2; #being nice to googles server } my $browser; sub do_GET { $browser = LWP::UserAgent->new() unless $browser; $browser->agent('Mozilla/5.0'); my $uri = URI->new('http://www.google.com/search'); $uri->query_form('q' => $_[0]); my $resp = $browser->simple_request (GET $uri); #THIS IS LINE 34 return ($resp->content, $resp->status_line, $resp->is_success, $re +sp) if wantarray; return unless $resp->is_success; return $resp->content; }
Here is my error from the script:
TiB17:~/scripts/perl/lwp theloanarranger$ 2-6 friend Can't locate object method "GET" via package "URI::http" at /Users/the +loanarranger/scripts/perl/lwp/2-6 line 34.

Please help,
-Matt

In reply to screen scraping google by theloanarranger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.