Hi,

I am trying to scrape this page and seems i cant get the valid '__VIEWSTATE' or even '__EVENTVALIDATION' (fields), here's my code:

use strict; use warnings; use HTML::TreeBuilder; use WWW::Mechanize; use URI::Escape; my $agent = WWW::Mechanize->new(); $agent->get('http://www.usgbc.org/myUSGBC/Members/MembersDirectory.asp +x?PageID=2011&CMSPageID=140'); $agent->form_name('frmMemberDirectory'); $agent->field('ddlCategory', ''); $agent->field('ddlState', ''); $agent->field('ddlCountry', 'US'); $agent->field('txtCompanyName', ''); $agent->click('btnSearch'); my $node = HTML::TreeBuilder->new(); $node->parse( $agent->content ); my $val_id = $node->find_by_attribute( id => '__EVENTVALIDATION'); my $validation = $val_id->attr('value'); my $state_id = $node->find_by_attribute( id => '__EVENTVALIDATION'); my $view_state = $state_id->attr('value'); $validation = uri_escape( $validation ); $view_state = uri_escape( $view_state ); my $id = '__EVENTTARGET=dgMembers%24ctl01%24ctl11&__EVENTARGUMENT=&__V +IEWSTATE='. $view_state . '&txtCompanyName=&ddlCategory=&ddlState=&ddlCountry=US&__EVENT +VALIDATION='. $validation; $agent->post('http://www.usgbc.org/myUSGBC/Members/MembersDirectory.as +px?PageID=2011&CMSPageID=140', Content => $id); print $agent->content();

Someone from this page said that 'encode' will solve the problem, i just have no idea what he means with 'encode'.

thanks

In reply to scraping ASP page, __VIEWSTATE problem by Anonymous Monk

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.