擅长:python、mysql、java
<p>我建议使用<a href="http://docs.python-requests.org/en/latest/" rel="nofollow">Requests for Humans</a>而不是urllib2。它使用起来更简单,也更明显。在</p>
<p>有时站点不支持基本的HTTP授权,即假设在每个请求的头中发送凭据。相反,他们需要在登录页面上使用凭证进行发布。此POST在服务器上验证,如果凭据正确,服务器将返回“setcookie:name=value”响应,请求浏览器保存Cookie。然后使用这个cookie来标识经过身份验证的客户端。在</p>
<p>看来,这是你的案子。在您的示例中,您需要向<a href="http://www.content.alternative.ac.nz/index.php/alternative/login/signIn" rel="nofollow">http://www.content.alternative.ac.nz/index.php/alternative/login/signIn</a>发出POST请求,使用您拥有的凭据设置参数“login”和“password”。然后从响应中检索cookie并将其添加到下一个请求中,如<a href="http://docs.python-requests.org/en/latest/user/quickstart/#cookies" rel="nofollow">this</a>。在</p>