Adding a cookie

K

koranthala

Hi,
I am creating a webscraper for a specific web site for an
application.
Now, that website has a specific cookie which needs to be set in
the request. Otherwise, the website is redirected.
I have been trying for the last 6 hours to add a cookie to the
HTTP request, but to no avail.
I tried mechanize for some time, then found the cookielib module
which again is a copy of it.
For such a small thing, the whole setup seems to be too
complicated.

The only way I could get any cookie in using the extract_cookies
from a cookiejar. But that will not help me because I want to add one
cookie - not get cookie from req and send it back.

Can anyone help me out?
 
J

Jens Müller

Hi,
I am creating a webscraper for a specific web site for an
application.
Now, that website has a specific cookie which needs to be set in
the request. Otherwise, the website is redirected.
I have been trying for the last 6 hours to add a cookie to the
HTTP request, but to no avail.

You just need to send the cookie's value in the HTTP header.
E.g. urllib2 can do this like this:
request = urllib2.Request(url, None, {'Cookie': '$Version="1";
cookieName="CookieValue"; $Path=/cookiePath'})

Regards,
Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top