使用Python进行基于表单的身份验证

2024-09-29 22:45:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用在Kent's Korner中读取的代码进行基于表单的身份验证。至少我被告知我正在阅读的网站是基于表单的认证。在

但我似乎无法通过登录页面。我使用的代码是

Import urllib, urllib2, cookielib, string

# configure an opener that will handle cookies
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
urllib2.install_opener(opener)

# use the opener to POST to the login form and the protected page
params = urllib.urlencode(dict(username='user', password='stuff'))
f = opener.open('http://www.hammernutrition.com/forums/memberlist.php?mode=viewprofile&u=1323', params)
data = f.read()
f.close()
f = opener.open('http://www.hammernutrition.com/forums/memberlist.php?mode=viewprofile&u=1323')
data = f.read()
f.close()

Tags: theto代码comhttp表单wwwparams

热门问题