punitpawar has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I wanted to know if there exists any way to extract cookies from a current browser session ?
Basically I wanted to make use of these cookies that I extract as an input to API calls.
Online I see information about setting cookies and using them , but I do not want to set cookies, I want to make use of cookies that are currently generated for an existing session
Any help on this will be great....
  • Comment on How to extract cookies from an existing browser session

Replies are listed 'Best First'.
Re: How to extract cookies from an existing browser session
by hippo (Archbishop) on Jun 10, 2016 at 17:08 UTC

    The standard module for this is HTTP::Cookies. You can use the any of the save, scan or as_string methods to extract cookie data from the jar depending on your requirements.

Re: How to extract cookies from an existing browser session
by kennethk (Abbot) on Jun 10, 2016 at 18:16 UTC
    hippo's response will be useful if you are doing all your interaction via Perl. However, if you need to extract a cookie from an existing browser session, you'll need to use browser-specific debugging tools. I usually use Firebug for Firefox.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      I don't have experience with Firebug. I have worked with the Firefox cookies DB, named amazingly enough cookies.sqlite in the Mozzila file hierachy. SQLite is actually quite popular in many apps and all smart phones have some form of it.

      I use SQlite Manager plug in to firefox. If you install that add-in, it will know how to find the cookies SQL file and you can see what's there. Of course PERL DBI::SQLite works great.

      Just an idea... Probably doesn't solve the OP's problem of session specific cookies, but this can show all the cookies.

        I love using SQLite and the associated Firefox plugins, but given the depth of experience suggested by the post, I figured the Firebug UI would greatly facilitate the OP's goal.

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: How to extract cookies from an existing browser session
by $h4X4_|=73}{ (Monk) on Jun 10, 2016 at 21:29 UTC

    You can get all the cookies with the environment variable.

    my $raw_cookies = $ENV{'HTTP_COOKIE'} || $ENV{'COOKIE'} || '';

      You can get all the cookies with the environment variable.

      my $raw_cookies   = $ENV{'HTTP_COOKIE'}  || $ENV{'COOKIE'} || '';

      Only if you happen to work with a CGI interface on the server side. On the client side, this will not work at all, and most other ways of interfacing with a webserver don't put cookies into the environment.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        The OP was not clear on what interface they where using. But you are right.
        If they want to get cookies from chrome will be a lot trickier then IE. Some people use this for chrome cookies SQLite Database Browser.