in reply to Getting data from an ASPX generated web page

Here is some code that goes toward your stated goal. I leave it to you to read and abide by the site TOS

use strict; use warnings; use WWW::Mechanize; use HTTP::Cookies; my $url = 'http://target-site.com'; my $cookies = HTTP::Cookies->new( file => "cookies.dat" ); my $mech = WWW::Mechanize->new( cookie_jar => $cookies ); $mech->get($url); my ($button) = $mech->find_all_inputs( type => 'image', name_regex => qr/yesButton$/, ); if (defined $button) { print "clicking button...\n"; $mech->click($button->{name}); $cookies->save; } my $response = $mech->content();

The first time it runs, you'll see 'clicking button...'. On subsequent invocations, this step should be avoided because the cookie will be reused

Replies are listed 'Best First'.
Re^2: Getting data from an ASPX generated web page
by billycote (Novice) on Jul 19, 2013 at 20:05 UTC
    Thanks so much! I feel like it's almost there. Just having a bit of trouble saving the cookie. I see it but for whatever reason it's not getting saved as I think it should be Here's my code:
    use strict; use warnings; use WWW::Mechanize; use HTTP::Cookies; my $url = 'http://emma.msrb.org/MarketActivity/RecentTrades.aspx'; my $cookies = HTTP::Cookies->new( file => "cookies.dat",autosave => 1, + ignore_discard => 1 ); my $mech = WWW::Mechanize->new( cookie_jar => $cookies ); $mech->proxy(['http'], 'http://http.proxy.fmr.com:8000'); my $response = $mech->get($url); $cookies->save( "cookies.dat"); if ($mech->success()){ print "Successful Connection\n"; } else { print "Not a successful connection\n"; } my ($button) = $mech->find_all_inputs( type => 'image', name_regex => qr/yesButton$/, ); print("button = $button->{name}\n"); if (defined $button) { print "clicking button...\n"; $mech->click($button->{name}); $cookies->save( "cookies.dat"); $mech->dump_text; }
    when I run it everything looks good except that this is wat I'm getting from the dump_text method.

    Object movedHTTP/1.1 302 Found Date: Fri, 19 Jul 2013 20:03:11 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 4.0.30319 Location: http://emma.msrb.org/MarketActivity/RecentTrades.aspx Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 170 Connection: close Set-Cookie: Disclaimer=Ratings; expires=Thu, 19-Jul-2063 20:03:11 GMT; path=/ Object moved to here.

    and nothing is getting into the cookies.dat file besides #LWP-Cookies-1.0 Frustating. I thought maybe I should call the get method again but that does nothing different. I'm sure I'm just missing something and again thanks so much for your help.