I'm trying to use get practice by writing a script that goes on a site, uses the forms on the site to choose a country, and scrape the desired information. Here's what I have.
#!C:/Perl/bin -w use LWP::UserAgent; use HTML::Parser; use strict; use HTTP::Request::Common; my %form = "country_form_0"; my $i = 0; my $agent = LWP::UserAgent->new; $agent->timeout(60); my @fields = ("country", "years1%5B%5D","c_tab","idbtable"); my $url = "http://www.census.gov/ipc/www/idb/country.php"; my @countries=("GI","GR","GL","GJ","GQ","GT","GK","GV","PU","GY","HA", +"HO","HK","HU","IC"); my @years =("2000","2001","2002","2003","2004","2005","2006","2007","2 +008","2009","2010"); my @tabs =("0","1","2"); for(1..4){ my $response = $agent-> post($url, $forms [ "country" => $countries[$i], "years1%5B%5D" => $years[0], "c_tab" => '0', "idbtable" => '0' ]); my $cont = $agent->request($response); print "$cont"; $i++; }
For some reason though, the script isn't working. I am getting the error "Global symbol @forms requires explicit name at etc..."



I'm pretty sure that I am using hashes wrong and that is causing the problem, but I'm not sure how to fix it. Any suggestions?



Similarly, how should I better write this? This can't be the best to accomplish this, right?

Thanks for all the help.





On a completely unrelated topic, what is with the painfully slow page load time? Is it just me? Or does everyone have this problem?

In reply to Data Aggregation by hodge-podge

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.