我需要帮助使用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()
我一直在努力解决这个问题,请帮忙。