in reply to Re^18: Need help with WWW::Mechanize and Chrome cookies
in thread Need help with WWW::Mechanize and Chrome cookies
Corion, forget the JavaScript for now. The goal is to use a single method to download all type of files (images, pdfs, CSVs etc..)
According to the documentations, the following method should be able to do it.
According to the documentations, the following method should be able to do it.
Unfortunately this method works only with files that the browser normally does not load such as (.csv). If you use this method with images (.jpg etc...) or PDFs (.pdf) the documents will load in the browser and the download fails. This exact same task has worked with WWW::Mechanize using the following methodmy @links = $mech->find_all_links(url_regex => qr/\.pdf/i); my @urls = map { $_->url_abs } @links; foreach (my $foo @urls ) { my $abs_path = "C:/path"; $mech->set_download_directory( $abs_path ); $mech->get($foo); }
The workaround that you have suggested below didn't work with PDFs and CSVs. it worked with images only.my $filename = "C:/path/filename"; my $foo = "http link"; $mech->get($foo, ':content_file'=>$filename);
my $response = $mech->get($url); my $c = $mech->content; # Dummy request to initialize everything open my $output, '>:raw', '/tmp/output.jpg'; print { $output } $response->decoded_content;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^20: Need help with WWW::Mechanize and Chrome cookies
by Corion (Patriarch) on Jul 27, 2021 at 19:20 UTC | |
by bakiperl (Beadle) on Jul 28, 2021 at 15:24 UTC | |
by Corion (Patriarch) on Jul 28, 2021 at 15:28 UTC |
In Section
Seekers of Perl Wisdom