Using Python 2.1 to download asp www pages that require cookies : My solution
zugz.public at DELETEMEcwcom.net
Fri Jan 18 15:45:14 CET 2002
"bernie" <bernie at 3captus.com> wrote in message
news:3C480677.987A7334 at 3captus.com...
> Hi Zugu,
> This is the case where you cannot just use urllib.urlopen. The page you
> trying to get is actually sending you a session cookie and excepted you to
> send that cookie to it when you try to get the page.
> The following code should work:
> import urllib
> class AppURLopener( urllib.FancyURLopener):
> def __init__( self, cookie=None, *args):
> apply( urllib.FancyURLopener.__init__, (self,) + args)
> if cookie:
> self.addheader( "Cookie", cookie)
> _cookie = "ASPSESSIONIDGGGQGOSO=EEKFJBBCFBDCAFJGPDKMLJDO"
> urllib._urlopener = AppURLopener( _cookie)
> print a.read()
Thanks for the solution, it's shorter and more to the point than the
solution I found elsewhere.
Now I just have to puzzle out why it works :)
More information about the Python-list