Hi,
I need perl code for getting cookie information.if anybody knows this ,kindly let me know. I am looking forward for this.
11 1794
This is the one place that has more information than anyone. Cookie's
Enjoy,
- Miller
The standard CGI module also handles cookies, see the CGI documentation for details.
Hi,
I tried with many examples , But unable to get that cookies information.
Please send the sample code for cookie information for google site.
Cheers
Bhuvan
Hi Bhuvan,
The documentation linked to above is clear. If you're having problems, describe your programming environment and show us the code that you are trying to get to work. We can then help you debug and diagnose what your problem is.
What have you tried so far? Show us.
- Miller
Hi Miller,
Please find the sample perl code for to get the cookie information for google site. -
use LWP::UserAgent;
-
use HTTP::Cookies::Microsoft;
-
use HTTP::Request;
-
# construct objects
-
my $ua = LWP::UserAgent->new;
-
my $cookie_jar = HTTP::Cookies::Microsoft->new;
-
-
my $request =HTTP::Request->new(POST => 'http://www.google.co.in');
-
my $response = $ua->request($request);
-
$cookie_jar->add_cookie_header( $request );
-
$cookie_jar->extract_cookies( $response ) ;
-
Note:In the above code we should give the print command for displaying the cookie information. But here,i have no idea how to display the same information.
If anything wrong,please correct me.It's very argent for me. Please do the needful.
Cheers
Bhuvan
- use LWP::UserAgent;
-
use HTTP::Cookies;
-
use HTTP::Request;
-
use Data::Dumper;
-
my $ua = LWP::UserAgent->new;
-
$ua->agent('Mozilla/5.0');
-
my $cookie_jar = HTTP::Cookies->new;
-
-
my $request =HTTP::Request->new(GET => 'http://www.google.co.in');
-
my $response = $ua->request($request);
-
$cookie_jar->add_cookie_header( $request );
-
$cookie_jar->extract_cookies( $response ) ;
-
print Dumper \$cookie_jar;
Hi KevinADC,
Thanks a lot.I got it. But i have doubts as given below.
1. What is this meaning of $ua->agent('Mozilla/5.0')
2. Why we need use "use Data::Dumper" package?
3. Can we get only cookie ID and Expire date?
Please explain the contents of Cookie information in Result. -
Result:
-
$VAR1 = \bless( {
-
'COOKIES' => {
-
'.google.co.in' => {
-
'/' => {
-
'PREF' => [
-
0,
-
'ID=cf620eca6ea2bc24:TM=1175246752:LM=1175246752:S =GJB0XsrEEVk97uZ9',
-
undef,
-
1,
-
undef,
-
2147368447
-
]
-
}
-
}
-
}
-
}, 'HTTP::Cookies' );
-
Thanks a lot.I got it. But i have doubts as given below.
1. What is this meaning of $ua->agent('Mozilla/5.0') Google does not like people hitting their sites with bots, which is really what this is. If you do not define a user agent (a web browser in other words) google might not send any response back. The line of code above fools google into thinking you are using the Mozilla/5.0 browser.
2. Why we need use "use Data::Dumper" package? That is just an easy way to dump the contents of the cookie data, which is returned as a reference to a hash.
3. Can we get only cookie ID and Expire date?
There is no expire date, it appears to be a cookie that just gets discarded. You can get the cookie data like this: - use LWP::UserAgent;
-
use HTTP::Cookies;
-
use HTTP::Request;
-
use Data::Dumper;
-
my $ua = LWP::UserAgent->new;
-
$ua->agent('Mozilla/5.0');
-
my $cookie_jar = HTTP::Cookies->new;
-
my $request =HTTP::Request->new(GET => 'http://www.google.co.in');
-
my $response = $ua->request($request);
-
$cookie_jar->add_cookie_header( $request );
-
$cookie_jar->extract_cookies( $response ) ;
-
$cookie_jar->scan(sub {
-
my ( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $expires, $discard) = @_;
-
print qq~$version, $key, $val, $path, $domain, $port, $path_spec, $secure, $expires, $discard~;
-
});
It's up to you to figure out what to do with:
$version, $key, $val, $path, $domain, $port, $path_spec, $secure, $expires, $discard
Hi,
Thanks Kevin.
Please clarify for the following questions in given code.
1. What is the use of scan()
2. Why do we need sub function
3. what is meaning of qq~ in the print command.
code:
$cookie_jar->scan(sub {
my ( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $expires, $discard) = @_;
print qq~$version, $key, $val, $path, $domain, $port, $path_spec, $secure, $expires, $discard~;
});
Bhuvan
scan() is a method of HTTP::Cookies. It's covered in the module documentation.
sub{} is just an annonymous sub routine in perl. The scan() method expects a reference to a sub as it's argument, so you have to use a reference to a named sub ( scan(\&namedSub) ) or an annonymous sub, which is a reference.
Annonymous subs are good for short functions that do one thing and don't really merit being a named sub routine/function all their own.
qq is a quoting operator. You can look that up on the perldoc website: Quote and Quote like Operators Sign in to post your reply or Sign up for a free account.
Similar topics
by: bagsmode |
last post by:
Hi,
I'm trying to set a session cookie and then redirect, however I get the
error:
Status: 302 Moved Location: /index.cgi
I thought I recall getting an error like this when I first tried...
|
by: Matt |
last post by:
I want to know what's the differences between session cookie and regular
cookie.
In ASP, when we create cookie, we do the following to identify an user:
Response.Cookies("name") = value
Is...
|
by: Shannon Jacobs |
last post by:
I'm doing some trivial surveys, and I want to know if the same user
answers twice. Can't really know that, but at least I thought I could
check for the same browser/computer combination by using a...
|
by: neerolyte |
last post by:
how would i go about setting a cookie in javascript that can be read in
javascript on the next page load, but will NOT be passed to the server?
|
by: Mark |
last post by:
I am designing a game for a forum. When the user has finished playing
I need to save their data to a cookie then navigate to a page which
holds their score data (I can't have both sets of data on...
|
by: Marco Krechting |
last post by:
Hi All,
I have a page with a list of hyperlinks.
I want to save information in a cookie about the fact that I entered an
hyperlink or not.
When I click one of the hyperlinks I want this stored...
|
by: nico |
last post by:
I store the authenticated user in a session cookie. This cookie expires after
an hour. Now for some reason sometimes the client browser decides not to send
the session cookie information with a new...
|
by: junOnline |
last post by:
Hi, I am developing an asp.net 2.0 application using visual studio 2005 on my
computer and I am getting very inconsistent results when I test on my
computer versus from other computers.
The...
|
by: Alessandro Fachin |
last post by:
Hi, i am trying to forge a new cookie by own with cookielib. But i don't
still have success. This a simply code:
import cookielib, urllib, urllib2
login = 'Ia am a cookie!'
cookiejar =...
|
by: =?Utf-8?B?SlA=?= |
last post by:
I need to design a WS that will after authenicating the user, create a cookie
on the users PC that made the request. All the code I keep finding is how to
get a WS to read a cookie, I need it to...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |