本文整理匯總了Python中Cookie.BaseCookie.keys方法的典型用法代碼示例。如果您正苦於以下問題:Python BaseCookie.keys方法的具體用法?Python BaseCookie.keys怎麽用?Python BaseCookie.keys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cookie.BaseCookie
的用法示例。
在下文中一共展示了BaseCookie.keys方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: do_login
# 需要導入模塊: from Cookie import BaseCookie [as 別名]
# 或者: from Cookie.BaseCookie import keys [as 別名]
def do_login(u, login, pwd):
conn = httplib.HTTPConnection(u.hostname, u.port)
conn.request('GET', u.path)
r = conn.getresponse()
if r.status != 200:
raise Exception, r.status, r.reason
h = pymayhem.FormRipper()
h.feed(r.read())
f = findlogin(h.forms)
if f is None:
raise ValueError, 'login form not found'
f['sausr'] = login
f['sapwd'] = pwd
params = f.get_form_data()
headers = {'Content-type': 'application/x-www-form-urlencoded',
'Referer': u.geturl(),
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-us,en;q=0.5'
}
lu = urlparse(f.action)
conn = httplib.HTTPConnection(lu.hostname, lu.port)
conn.request('POST', lu.path, params, headers)
r = conn.getresponse()
if r.status != 302:
raise ValueError, 'bad response', r
cookie = None
location = None
for (k, v) in r.getheaders():
if k == 'set-cookie':
cookie = v
elif k == 'location':
location = urlparse(v)
c = Cookie(cookie)
c = c.output(c.keys(), '', ', ').strip()
q = location.query
return (c, q)