Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Reading a cookie from an active browser session

by xorl (Deacon)
on Nov 07, 2013 at 16:58 UTC ( [id://1061601]=perlquestion: print w/replies, xml ) Need Help??

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

My work's VPN requires me to first login to a website, get a specific cookie and then pass that to the vpn software (This Juniper VPN if anyone is wondering and I'm using Linux).

I don't want to have to go searching through Firefox's preferences to find by hand find the cookie I need. I thought I'd use perl to read cookies.txt, but of course there doesn't seem to be a cookies.txt any more.

I then played around with sqlite3 (getting DBD::SQLite working was also a pain). It seems the cookie isn't actually saved to the file but is only in some active memory or something. I can find it in Firefox in the list of all cookies. There are also some cookies specific to our domain that are in both the file and while the browser is open. So something does get saved just not the specific cookie I need.

Any idea how I might go about retrieving this cookie? I'm willing to switch browsers if that might help. There's also something on github that tries to screen scrape the vpn website and capture the cookie from there, but it doesn't at all work with the site I have to log into. If I'm going about this (the vpn login) totally wrong let me know ideas on that too.

Thanks in advance.

  • Comment on Reading a cookie from an active browser session

Replies are listed 'Best First'.
Re: Reading a cookie from an active browser session
by Corion (Patriarch) on Nov 07, 2013 at 17:00 UTC
      So I installed the mozrepl plugin. telnet localhost 4242 seems to work fine. So I went to install the Perl module, but it won't install:
      Result: FAIL Failed 81/86 test programs. 14/90 subtests failed. make: *** [test_dynamic] Error 2 CORION/WWW-Mechanize-Firefox-0.74.tar.gz one dependency not OK (MozRepl::RemoteObject); additionally test harne +ss failed /usr/bin/make test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports CORION/WWW-Mechanize-Firefox-0.74.tar.gz Running make install make test had returned bad status, won't install without force Failed during this command: ZIGOROU/MozRepl-0.06.tar.gz : make_test NO CORION/MozRepl-RemoteObject-0.37.tar.gz : make_test NO one depen +dency not OK (MozRepl) CORION/WWW-Mechanize-Firefox-0.74.tar.gz : make_test NO one depen +dency not OK (MozRepl::RemoteObject); additionally test harness faile +d cpan[2]> reports CORION/WWW-Mechanize-Firefox-0.74.tar.gz Distribution: C/CO/CORION/WWW-Mechanize-Firefox-0.74.tar.gz CPAN::DistnameInfo not installed; cannot continue

      From what i could tell most fail with:

      Can't locate MozRepl/RemoteObject.pm in @INC

      So I tried installing MozRepl::RemoteObject

      Result: PASS CORION/MozRepl-RemoteObject-0.37.tar.gz Tests succeeded but one dependency not OK (MozRepl) CORION/MozRepl-RemoteObject-0.37.tar.gz [dependencies] -- NA Running make install make test had returned bad status, won't install without force Failed during this command: ZIGOROU/MozRepl-0.06.tar.gz : make_test NO CORION/MozRepl-RemoteObject-0.37.tar.gz : make_test NO one depen +dency not OK (MozRepl)
      so I tried installing just MozRepl
      Result: FAIL Failed 5/14 test programs. 10/42 subtests failed. make: *** [test_dynamic] Error 255 ZIGOROU/MozRepl-0.06.tar.gz /usr/bin/make test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports ZIGOROU/MozRepl-0.06.tar.gz Running make install make test had returned bad status, won't install without force Failed during this command: ZIGOROU/MozRepl-0.06.tar.gz : make_test NO

      There's so much gobliktygook from that one I can't make heads or tails as to what tests failed or why. I'd post it here but it is really really really long and I wouldn't expect anyone to look through it.

      So basically I need another solution :(

        MozRepl is not maintained by me. It fails its tests, I think mostly on Windows for a long time.

        I recommend you force-install MozRepl and then continue with the rest.

        I just installed WWW::Mechanize::Firefox v0.74 using cpan on Windows 7 under Cygwin, with no -force and no problem.
Re: Reading a cookie from an active browser session
by jethro (Monsignor) on Nov 07, 2013 at 17:09 UTC

    wget and curl have options for cookie download. If not, a perl script to access the web site (based on WWW::Mechanize or WWW::Mechanize::Firefox) should still be better than mucking in the innards of firefox

    A really hacky way to get at the cookie would be to use something like tcpdump to record your traffic with the website and extract the cookie from that

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found