Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by Corion (Patriarch)
on Jul 11, 2021 at 15:10 UTC ( [id://11134916]=note: print w/replies, xml ) Need Help??


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

Yes. So what is the value of $foo? Did you print it? Is the loop necessary for the bug to happen, or does the error happen with the hardcoded value for $foo as well?

From the URL you sent to me, it seems that WWW::Mechanize returns absolute URLs, while WWW::Mechanize::Chrome returns whatever URLs are contained in the file. Simple printing of the values can confirm that to you.

Until WWW::Mechanize::Chrome achieves API parity with WWW::Mechanize in that part, consider converting the URL to absolute yourself.

Replies are listed 'Best First'.
Re^13: Need help with WWW::Mechanize and Chrome cookies
by bakiperl (Beadle) on Jul 11, 2021 at 16:50 UTC
    I modified the code to eliminate the loop and I changed the URL to absolute.
    my @urls = map { $_->url_abs } @links;
    The error message went away but these calls still don't return anything.
    $mech->get($foo, ':content_file'=>$filename); my $file_content = $mech->get($foo);

      Why do you expect the following to work for WWW::Mechanize::Chrome? This is not a documented call:

      $mech->get($foo, ':content_file'=>$filename);

      I wonder why you say that the following "return anything":

      my $file_content = $mech->get($foo);

      ->get() is documented to return a response, so I suggest that you print it, or inspect it using Data::Dumper.

        Corion,
        I get an empty string when I print the file content.
        my $file_content = $mech->get($foo); print $file_content;
        Here is the result returned by the Data::Dumper
        $VAR1 = bless( { '_headers' => bless( { '::std_case' => { 'x-frame-opt +ions' => 'X-Frame-Options', 'expect-ct' +=> 'Expect-CT', 'content-sec +urity-policy' => 'Content-Security-Policy', 'x-xss-prote +ction' => 'X-XSS-Protection', 'x-content-t +ype-options' => 'X-Content-Type-Options', 'strict-tran +sport-security' => 'Strict-Transport-Security', 'referrer-po +licy' => 'Referrer-Policy' }, 'content-security-policy' => ' +default-src \'self\' data: https: \'unsafe-eval\' \'unsafe-inline\'', 'date' => 'Sun, 11 Jul 2021 19 +:46:11 GMT', 'strict-transport-security' => + 'max-age=31536000; includeSubDomains', 'etag' => '"06c81313776d71:0"' +, 'expect-ct' => 'enforce, max-a +ge=30, report-uri="https://{$subdomain}.report-uri.com/r/d/ct/enforce +"', 'x-frame-options' => 'SAMEORIG +IN', 'server' => '', 'x-content-type-options' => 'n +osniff', 'x-xss-protection' => '1;mode= +block', 'accept-ranges' => 'bytes', 'referrer-policy' => 'no-refer +rer' }, 'HTTP::Headers' ), '_request' => undef, '_content' => '', '_rc' => 304, '_msg' => 'Not Modified' }, 'HTTP::Response' );
        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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found