我需要使用urllib帮助验证登录到这个站点的帮助。我使用Python 3,但我愿意恢复到2.x.
这是我所知道的(基本上来自文档),它没有提供错误,但没有登录。
file =open("loggedinsource.html",'wb')
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='kalahari.net',uri='https://www.kalahari.net/profile/pipeline/signin.aspx?',user='myuser',passwd='mypass')
opener = urllib.request.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)
f=urllib.request.urlopen('https://www.kalahari.net/profile/pipeline/signin.aspx?')
page=f.read()
file.write(page);
file.close()我一直在为这个问题苦苦挣扎,请任何帮助。