in reply to Re^2: 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?

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.


🦛

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

Replies are listed 'Best First'.
Re^4: Why does HTTP::Cookies and/or LWP add Google cookies to my cookie jar when visiting another site?
by Polyglot (Chaplain) on Apr 27, 2022 at 15:23 UTC
    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