in reply to Re^2: LWP and Mechanize
in thread LWP and Mechanize

How to print out content during the else condition?

That was in my edit2 section: else {die $response->status_line . ($response->content||'');}

Or, putting it into your whole script:

use strict; use warnings; use LWP::UserAgent(); my $ua = LWP::UserAgent->new(timeout => 10); $ua->env_proxy; my $response = $ua->get('https://www.sec.gov/Archives/edgar/full-index +/2019/QTR1/master.idx'); open(OUT, ">" . "master") or die "Cannot open master"; if ($response->is_success) {print OUT $response->decoded_content; } else {die $response->status_line . ($response->content||'');} close OUT;

Replies are listed 'Best First'.
Re^4: LWP and Mechanize
by perlmike (Novice) on May 21, 2022 at 21:30 UTC

    I see now. Can you tell me how to set up the user agent?

        I know LWP:: UserAgent, but I cannot figure out how to set it up. Thanks