July 2002
Intermediate to advanced
608 pages
15h 46m
English
Credit: Andy McKay
You need to find a specific IE cookie.
Cookies that your browser has downloaded contain potentially useful information, so it’s important to know how to get at them. With IE, you need to access the registry to find where the cookies are, then read them as files:
from string import lower, find import re, os, glob import win32api, win32con def _getLocation( ): """ Examines the registry to find the cookie folder IE uses """ key = r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' regkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, key, 0, win32con.KEY_ALL_ACCESS) num = win32api.RegQueryInfoKey(regkey)[1] for x in range(num): k = win32api.RegEnumValue(regkey, x) if k[0] == 'Cookies': return k[1] def _getCookieFiles(location, name): """ Rummages through all the filenames in the cookie folder and returns only the filenames that include the substring 'name'. name can be the domain; for example 'activestate' will return all cookies for activestate. Unfortunately, it will also return cookies for domains such as activestate.foo.com, but that's unlikely to happen, and you can double-check later to see if it has occurred. """ filemask = os.path.join(location, '*%s*' % name) filenames = glob.glob(filemask) return filenames def _findCookie(files, cookie_re): """ Look through a group of files for a cookie that satisfies a given compiled RE, returning the first such cookie found. """ for file in files: data ...
Read now
Unlock full access