简体   繁体   中英

Loading IE Cookies into Perl's WWW::Mechanize

I'm having a heck of a time with this...

I am trying to connect to a website which requires a login. I can obviously go directly to the page without logging in because IE has a cookie to do so.

I am working on a script that will be run by people other than myself, so I don't want to send around a file with my login information. Ideally, others wouldn't have to put that information in as well.

Here is the small, relevant part of the code. I just want to load the cookies from IE and print them (since I assume once they are in there, they will be accessed properly).

I've searched for hours and have even read people claim that this loads cookies. I see it being able to store cookies now, but not load existing cookies on my computer.

#!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
use HTTP::Cookies::Microsoft;
use Win32::TieRegistry(Delimiter => "/");

my $cookies_dir = $Registry-> {"CUser/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Cookies"};
my $cookie_jar = HTTP::Cookies::Microsoft->new(file => "$cookies_dir\\index.dat",'delayload'=>0,);
my $mech = WWW::Mechanize->new(cookie_jar => $cookie_jar);
print "Set Cookie Jar?\n", $cookie_jar->as_string, "\n";
print "Set Cookie Jar?\n", $mech->cookie_jar->as_string, "\n";

Can I load existing cookies?

Is HTTP::Cookies::Microsoft not compatible with IE9? (Website lists IE6 and IE7, but hasn't been updated since 2002).

I don't even see where in this example or any example it actually LOADS existing cookies. If it is just a compatibility issue, what options are there for IE9? (I have to stick to IE9 since it is the support browser in this company)

Thanks!

With IE8 on my Windows XP system, cookies are in C:\\Documents and Settings\\userid\\Local Settings\\Temporary Internet Files . There is no index.dat , the cookies are in their own files.

I don't know where IE9 stores cookies .

However, if you are trying to automate something on a site where users log on via IE, and start your program, you can use Win32::IE::Mechanize or drive IE via Win32::OLE . See, for example, my blog post Using Win32::OLE with events to capture Internet Explorer screenshots with Perl . Information on the methods, properties, and events available, see InternetExplorer object documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM