in reply to Re: LWP::Simple... Enough for Site Query & Data Download?
in thread LWP::Simple... Enough for Site Query & Data Download?

I used the example code found at the WWW::Mechanize doc to test my wanted page:
use strict; use warnings; use WWW::Mechanize; my $outfilename = "data.txt"; open(TFILE,">$outfilename"); my $mech = WWW::Mechanize->new(); $mech->get( "http://bub2.meteo.psu.edu/wxstn/wxstn.htm" ); $mech->forms; print TFILE "$mech \n"; exit;

I was expecting a list of the available forms on that page, but got the following line of text instead:

WWW::Mechanize=HASH(0x18454fc)

Is this because my variable $mech is in scalar context and therefore returned a reference to the array holding the form id's?

Thanks

Replies are listed 'Best First'.
Re^3: LWP::Simple... Enough for Site Query & Data Download?
by Your Mother (Archbishop) on Jun 15, 2009 at 00:52 UTC

    Go through the docs a little more carefully. You're printing the mech object, not the forms. Try this instead-

    use WWW::Mechanize; use YAML (); my $mech = WWW::Mechanize->new(); $mech->get( "http://bub2.meteo.psu.edu/wxstn/wxstn.htm" ); print YAML::Dump [ $mech->forms ];

    Next stop: the docs for HTML::Form.

      Unfortunately I get the error,
      C:\Perl\scripts>perl -wc foo.pl Can't locate YAML.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at foo.pl line 6. BEGIN failed--compilation aborted at foo.pl line 6."
      when I run this code..?

        Sorry about that. I forget it's not a core module. Try this.

        use WWW::Mechanize; use Data::Dumper; $Data::Dumper::Terse = 1; my $mech = WWW::Mechanize->new(); $mech->get( "http://bub2.meteo.psu.edu/wxstn/wxstn.htm" ); print Dumper($mech->forms);