Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6123173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:59:03+00:00 2026-05-23T15:59:03+00:00

Using the WWW::Mechanize and HTTP::Cookies how would I extract the cookie past in the

  • 0

Using the WWW::Mechanize and HTTP::Cookies how would I extract the cookie past in the response from the server?

#usr/bin/perl 
#MagicLogin.pl

use warnings;
use strict;

use Win32::IE::Mechanize;
use HTTP::Message;
use WWW::Mechanize;
use HTTP::Request::Form;
use HTML::TreeBuilder 3.0;



my $url = 'http://magic.dstcorp.net/MagicDST/';

my $mech = WWW::Mechanize->new(cookie_jar => {});
$mech->agent_alias('Windows IE 6');

my $cookie_jar = new HTTP::Cookies;


my $res = $mech->get($url);
my $tree = new HTML::TreeBuilder;
$tree->parse($res->content);
$tree->eof;

my @forms = $tree->find_by_tag_name('form') or die "No form available";

my $f = HTTP::Request::Form->new($forms[0], $url);
my @fields = $f->allfields;
my $name = $f->name;
my $links = $f->link;
my $buttons = $f->buttons;
my $referrer = $f->referer;

print "Name: ", $name, "\nLink: ", $links, "\nFields: ", @fields,"\nButtons: ", $buttons, "\nReferrer: ", $referrer;

my $response = $mech->request($f->press("ok"));
my $cookie = $cookie_jar->extract_cookies($response);
print $response->content if $response->is_success;

print "Succesfully got url" if $mech->success;

#my $headers = new HTTP::Headers;
#my $cookie = $headers->header('Cookie:');
#print "Cookie:", $headers->referer;

#$mech->get($url);
#my @forms = $mech->forms;


#my $content = $mech->content;
my $output_content = 'MagicLogin.html';


#open Write ,">$output_content";
#print Write $content;

Output:

Name: frmLoginEmbedded
Use of uninitialized value $link in print at MagicLoginTest.pl line32.
Link:

Fields:
Buttons: 0
Use of uninitialized value $referre in print at MagicLoginTest.pl line 37.

Thanks in advance for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:59:04+00:00Added an answer on May 23, 2026 at 3:59 pm

    Mechanize already includes a cookie jar. You need not construct it manually.

    use Data::Dumper qw(Dumper);
    use WWW::Mechanize qw();
    my $m = WWW::Mechanize->new;
    $m->get(…);
    $m->cookie_jar; # returns a HTTP::Cookies object
    # e.g.
    print $m->cookie_jar->as_string;
    $m->cookie_jar->scan(sub { print Dumper \@_; })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using WWW::Mechanize to retrieve a form from a webpage: #!/usr/bin/perl use WWW::Mechanize; my
I'm trying to use WWW::Mechanize to extract some links from the HTML page using
Im using mechanize to parse http://www.hammacher.com/Category/Default.aspx?uq=Gifts-Under-30&all=True What xpath can I use to get to
I'm trying to login automatically in a website using Perl with WWW::Mechanize . What
I'm using Mechanize to extract the links from the page. To ease with development,
I want to search content from a site using WWW::Mechanize but to be able
Getting the following error in a JavaScript link using perl - WWW::Mechanize . Error
I am using perl modules WWW::Scripter (based on WWW::Mechanize ) with JavaScript plugin and
I am attempting to download a lot of files from http://www.sl.universalservice.org/funding/opendatasearch/Search1.asp using the Python
I am trying to write a Perl script using WWW-Mechanize. Here is my code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.