Ok, guys, I am new to perl and the forum, i hope this is not a capital offence ;)

Here is the problem.

I want to login via perl script to http://www.tennisinsight.com/match_previews.htm and download the page. I am stuck at login into the site via the script. I want to save all cookies generated in the process, the site uses cookies.

1 The site uses cookies to store login data.

2 The login form is triggered by javascript, but that is not important, because a simple web page on local server that containts only:

<form action="http://www.tennisinsight.com/myTI.php" method="POST"> <input name="username" type="text" size="25" /> <input name="password" type="password" size="25" /> <input name="mySubmit" type="submit" value="Submit!" /> </form>
given the right username and pass will send the needed data, and the site will redirect to main website page, user will be logged, and cookies created. In short, a simple post with correct data is all needed from client side. 3.I have successfully tried and fetched the page I need with curl, once the correct cookies were provided. ( I have converted FF3 db file to FF2 txt file and provided ot to curl) I think that posting to myTI.php, storing the returned cookies and then opening the page I need while reading the cookies will allow me to Here is the script I use to get cookies, I now it prints to stdout atm, still unsuccessful.
use warnings; use HTML::Tree; use LWP::Simple; use WWW::Mechanize; use HTTP::Request::Common; use Data::Dumper; my $username = "user"; my $password = "pass"; my $site_url = 'http://www.tennisinsight.com/myTI.php'; my $mech = WWW::Mechanize->new( autocheck => 1 ); # print $mech->content; my $response = $mech->post($site_url , [ 'username' => $username, 'password' => $password, ]) ; my $cookie_jar = HTTP::Cookies->new; $cookie_jar->extract_cookies( $response ); print $cookie_jar;
Seems I am missing something
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; # use HTTP::Cookies; # use HTML::Form; my $urlLog = "http://tennisinsight.com/myTI.php"; my $url = "http://www.tennisinsight.com/match_previews.htm"; my $mech = WWW::Mechanize->new( autocheck => 1, keep_alive => 115, 'Ti +meout' => '30',); my $cookie_file = "cookies.txt"; my $username = "usr"; #username VALUE my $password = "pss"; #password VALUE my $inputUser = "username"; #username KEY NAME my $inputPassword = "password"; #password KEY NAME $mech->post($urlLog, [ $inputUser => $username, $inputPassword => $pas +sword ]); $mech->cookie_jar->save($cookie_file); if (! -s $cookie_file){ $mech->post($urlLog, [ $inputUser => $username, $inputPassword => +$password ]); # Save the cookie from this session $mech->cookie_jar->save($cookie_file); } else { $mech->cookie_jar->load($cookie_file); $mech->get("http://www.tennisinsight.com/match_previews.htm"); } # Print to file my $output = $mech->content(); open(my $fh, '>', 'report.html'); print $fh $output; close $fh; print "done\n";
This works for me. After a bit of reading, and examining the the headers, I added keep alive to $mech and that solved it.

In reply to Save cookies after post method, perl, mechanize, redirect by deckoff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.