process web page with cookie
bernie
bernie at 3captus.com
Mon Jan 21 23:51:09 EST 2002
Hi Cyclotron,
The following code was posted for a similar question. All you needed
to change is _cookie and _url.
Basically, you needed urllib.FancyURLopener. This piece code was
before urllib2 was born. Now with urllib2 you can use build_opener(),
install_opener() and Request() to do the job in a more OO way. But
I am too lazy to write an example.
#!/usr/bin/env python
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"
_url =
"http://boards.gamers.com/messages/overview.asp?name=panther_xl&page=2"
urllib._urlopener = AppURLopener( _cookie)
a = urllib.urlopen( _url)
print a.read()
cyclotron wrote:
>
> Hi,
> I'm pretty new to Python but I figured out how to load/process web
> pages.
> My question is: How can I process web pages that need a cookie (e.g.
> with my username+password stored in <user at sitename.txt> cookie file)
> to load properly?
> I didn't manage to get this work.
> greetings
More information about the Python-list
mailing list