Using Python 2.1 to download asp www pages that require cookies : My solution

Zugz 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
are
> 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)
>
>
a=urllib.urlopen("http://boards.gamers.com/messages/overview.asp?name=panthe
r_xl&page=2")
>
> print a.read()

Hi bernie,

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 :)

Thanks again,
Zugz.






More information about the Python-list mailing list