Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^15: Need help with WWW::Mechanize and Chrome cookies

by bakiperl (Beadle)
on Jul 17, 2021 at 19:54 UTC ( [id://11135109]=note: print w/replies, xml ) Need Help??


in reply to Re^14: Need help with WWW::Mechanize and Chrome cookies
in thread Need help with WWW::Mechanize and Chrome cookies

Corion says: Did you set the download directory (download_directory option) in the constructor?
-----------

The download_directory finally worked after finding out that chrome does not support paths in this format c:/path...
The download path has to use the backslash instead ( c:\path... ).
my $downloads = = "C:\\path\\"; $mech->set_download_directory( $downloads); $mech->get($foo);
My final question is how to stop chrome browser from loading some documents so that the download can be executed with WMC. If a document (such as a jpg) is loaded in the browser, the file does not download.
Thank you for your patience.

Replies are listed 'Best First'.
Re^16: Need help with WWW::Mechanize and Chrome cookies
by Corion (Patriarch) on Jul 18, 2021 at 07:17 UTC

    If a file does not download, have you tried inspecting the HTTP::Response object you receive from the ->get() call?

    my $response = $mech->get($url); open my $output, '>:raw', '/tmp/output.jpg'; print { $output } $response->decoded_content;

    Edit: You might need to touch the ->content of the browser first so everything has time to initialize first:

    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;
      Corion,
      This code did the trick for image files but not for PDFs. I also noticed that it works only for simple urls in the page. It did not work for me when the images are displayed using JavaScript.
      I was hoping to find a way to block the browser from displaying the documents by using something like the Content-Disposition option.
      Content-Disposition: attachment; filename=$filename
      This has worked very well with WWW::Mechanize.
      Thank you.

        Your problem statement seems to continously change. I don't see/understand how you can get from "image download using its URL" to "image displayed using Javascript" without changing the problem entirely.

        Maybe you can come up with a small, self-contained program that reproduces your problem, and also shows the response you receive and also tell us what parts you have already investigated, instead of letting us guess. That way, we can more easily reproduce what you see and maybe suggest better approaches.

        If an image gets created using Javascript, you will have to fetch the image data from the browser memory, most likely by using some Javascript to fetch that image data. You can run arbitrary Javascript on a page using ->evaluate_in_page.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135109]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-29 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found