网站的注册是免费的:http://software.broadinstitute.org/gsea/login.jsp
我根据一些教程编写了登录网站的代码:
import requests
url = "http://software.broadinstitute.org/gsea/login.jsp"
# Fill in your details here to be posted to the login form.
payload = {
'j_username': 'xxx@gmail.com',
'j_password': 'password'
}
# Use 'with' to ensure the session context is closed after use.
s = request.session()
p = s.post(url, data=payload)
# print the html returned or something more intelligent to see if it's a successful login page.
print p, p.url, p.status_code
print 'is redirected: ', p.is_redirect
r = s.get("https://software.broadinstitute.org/gsea/msigdb/download_file.jsp?filePath=/resources/msigdb/6.2/msigdb_v6.2.xml")
# print r.text
print r, r.url, r.status_code
print 'is redirected: ', r.is_redirect
with open("lol.xml", "wb") as handle:
handle.write(r.content)
我不知道我是否必须填写密码,因为它是隐藏的?你知道吗
post命令返回200 OK,但我仍未登录:
<Response [200]> http://software.broadinstitute.org/gsea/login.jsp 200
is redirected: False
<Response [200]> https://software.broadinstitute.org/gsea/login.jsp 200
is redirected: False
好的,可能的错误源是具有错误字典键的负载。你知道吗
html代码如下所示:
<form id="loginForm" name="loginForm" action="j_spring_security_check" method="POST">
<table border="0" class="bodyfont" cellpadding="5" cellspacing="5">
<tbody><tr>
<td colspan="2" align="left">Items marked with <font color="red">*</font> are required.</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td><h3>Email: <font color="red">*</font> </h3></td>
<td><input id="email" type="text" name="j_username" value="">
<input id="password" type="hidden" name="j_password" value="password"></td>
</tr>
<tr>
<td> </td>
<td><input type="button" name="login" value="login" style="margin-top:10px;" onclick="validateForm()"></td>
</tr>
</tbody></table>
</form>
我错过什么了吗?为什么不登录?你知道吗
正如我在评论中提到的,当你想带着请求登录某个地方时,查看Chrome的Network标签中的日志是非常好的第一步。您的代码不起作用,因为您只是对post请求使用了错误的url!代码中也有一些拼写错误,例如:
request.session()
而不是requests.session()
。你知道吗总的来说,我也怀疑查看响应状态代码是否是判断登录是否有效的好方法。你知道吗
你可以用你想要的任何子域来替换这个url。。。
相关问题 更多 >
编程相关推荐