本文整理汇总了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)