in reply to Re: Why does HTTP::Cookies and/or LWP add Google cookies to my cookie jar when visiting another site?
in thread Why does HTTP::Cookies and/or LWP add Google cookies to my cookie jar when visiting another site?

Thank you for the clues. Upon investigation, emptying the cookie jar and retrying, the script now generates an error message which says:

./HTTP-Cookies.jar does not seem to contain cookies at /System/Library/Perl/Extras/5.12/HTTP/Cookies.pm line 432.

...and the file remains empty, except for this:

#LWP-Cookies-1.0

It was about this point that I remembered that I had pointed the script once, for testing purposes, at another website--one that I do not own. Evidently, the cookies in the jar remained permanently after that, which was not the behavior I had expected.

I was unable to install the module you recommended, unfortunately. I got only error messages, and it failed to install. Disappointing.

Now, why is it that the cookie jar seems necessary in order to complete the GET request? ... but maybe I'm just misunderstanding the process again.

Blessings,

~Polyglot~

  • Comment on Re^2: Why does HTTP::Cookies and/or LWP add Google cookies to my cookie jar when visiting another site?
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: Why does HTTP::Cookies and/or LWP add Google cookies to my cookie jar when visiting another site?
by hippo (Archbishop) on Apr 27, 2022 at 14:43 UTC
    Evidently, the cookies in the jar remained permanently after that, which was not the behavior I had expected.

    Persistently storing the cookies is the only reason to have a cookie jar present on the filesystem.


    🦛

      Yes, that would make sense to my mind if the cookie jar had been a 'system' file; but I had created it myself just for this particular script, and I, perhaps unreasonably, expected it to be temporary storage used only until the script had completed. Naturally, I'm learning, and thank you.

      Blessings,

      ~Polyglot~

        I think you can basically delete all lines from 'my $jar=...' onward and replace them with

        my $response= $browser->request($request); $response->is_success or die $response->status_line; return $response->decoded_content

        In other words, the in-memory cookie jar you got from cookie_jar({}) gives you cookie support already, and decoding the response body is a built-in feature, and you should check for http success before returning the content or else you could end up saving 404 message bodies.

        oh, and I also notice you call $browser->get before $browser->request. The first one is a redundant shorthand for a get request, and you aren't saving the response.

        Also, if you later decide that you need more advanced simulation of a browser, check out WWW::Mechanize