Adding a cookie

Jens Müller me4 at privacy.net
Sun Jan 17 09:17:21 EST 2010


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 




More information about the Python-list mailing list