Retrieving Cookies in HTML Documents : Parse HTML : Network PYTHON TUTORIALS


PYTHON TUTORIALS » Network » Parse HTML »

 

Retrieving Cookies in HTML Documents


import os
import urllib2
import cookielib
from urllib2 import urlopen, Request

cookieFile = "cookies.dat"
testURL = 'http://maps.google.com/'

cJar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cJar))
urllib2.install_opener(opener)

r = Request(testURL)
h = urlopen(r)
print h.info()

for ind, cookie in enumerate(cJar):
    print "%d - %s" (ind, cookie)

cJar.save(cookieFile)



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Network
» Parse HTML