Todd Chester has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
First, I am really, really new to Perl, so please don't address me like I know what I am doing. You need to directly correct me. I don't mind you calling me a Dumb A** as long as you answer the question.
I am trying to read and set my cookies. I get the following error:
Can't call method "extract_cookies" on an undefined value at ./GetJavaTest.pl line 53 (#1)If I remove the comment from line 51, a whole web page prints out. I don't get why I am trying to work on an "undefined value". There is tons of stuff in it. This is so frustrating!
The exact cookie I am trying to use is:
http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
Lines 1024 to 1029:
function acceptAgreement(windowRef, part){ var doc = windowRef.document; disableDownloadAnchors(doc, false, part); hideAgreementDiv(doc, part); writeSessionCookie( 'oraclelicense', 'accept-securebackup-cookie' ); }
What the heck (not my actual word) am I doing wrong???
Is there any way I can just write the cookie in like I can with wget? (See the code below for how to use wget.)
Many thanks,
-T
#!/usr/bin/perl # Test java wget style download of Java # wget --header "Cookie: # oraclelicense=accept-securebackup-cookie" # http://download.oracle.com/otn-pub/java/jdk/7u80-b15/jre-7u80-window +s-i586.exe # Notes: # This is going in a sub. Do not use "die" # The "echo" of this will be read by a Bash script. All debug # statements need to use STDERR # Known mistakes: the multimeg download need to go to a file # not a variable # cookies are not being transfered correctly # http://www.perlmonks.org/?node_id=456612 # http://lwp.interglacial.com/ch11_01.htm use strict; use warnings; use diagnostics; # use diagnostics "-verbose"; use Term::ANSIColor qw( BOLD RED RESET ); use LWP::UserAgent; use HTTP::Cookies qw ( extract_cookies ); use LWP::Protocol qw ( https ); use HTTP::Request qw ( request ); use constant MaxTime3 => scalar 3300; # Seconds # Indent here is so I don't have to put it back when it goes back into + a sub my $ua; my $response; my $content; my $request; my $cookie_jar; my $ClickHere = "http://download.oracle.com/otn-pub/java/jdk/7u80-b +15/jre-7u80-windows-i586.exe"; my $RevAddr = "http://www.oracle.com/technetwork/java/javase/down +loads/jre7-downloads-1880261.html"; $ua = LWP::UserAgent->new; $ua->cookie_jar ( {} ); $request = HTTP::Request->new('GET', "$RevAddr" ); print "\$request = ", $request -> as_string, "\n"; $response = $ua->simple_request($request); # print "\$response = ", $response -> as_string, "\n"; $cookie_jar->extract_cookies($response); $ua->timeout ( MaxTime3 ); $ua->show_progress ( 1 ); $response = $ua->get ( $ClickHere, ':content_file' => './eraseme.bi +n' ); print "\$ClickHere response = ", $response -> as_string, "\n";
|
|---|