使用Python请求传递登录名/密码 [英] Using Python Requests to pass through a login/password

查看:158
本文介绍了使用Python请求传递登录名/密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了相关的答案,但还没有找到行之有效的方法.我正试图从球队的CBS Sportsline页面上抓取一些幻想棒球的信息.

I have looked at related answers and I haven't found something that quite works. I'm trying to scrape some fantasy baseball information from my team's CBS Sportsline page.

我要发布登录名和密码,然后在使用get命令时,查看特定于我的帐户的数据.

I want to post the login and password and then when I use the get command, see the data specific to my account.

这是我尝试过的:

import requests

myurl = 'http://bbroto.baseball.cbssports.com/transactions'

payload = {
       'userid': '(my username)',
       'Password': '(my password)',
       'persistent': '1'}

session = requests.session()
p = requests.post(myurl, data=payload)

r = session.get(myurl)

print r.content

它给了我通用页面(好像我没有登录).

it gives me the generic page (as if I'm not logged in).

这是表单信息的样子:

<form method="post" action="/login/index" name="login_form" id="login_form" >
<input     type="hidden" name="dummy::login_form" id="dummy::login_form" value="1">
<input type="hidden" id="form::login_form" name="form::login_form" value="login_form">
<table id="table_login_form" class="formLayout"><input type="hidden" 
value="http://bbroto.baseball.cbssports.com/transactions" name="xurl" id="xurl"><input
type="hidden" value="150" name="master_product" id="master_product"><input 
type="hidden" value="cbssports" name="vendor" id="vendor"><tr id="row_userid"><td 
align="right"></td>
<td><table class="fieldLayout"><tr><td><input type="text" value="Email or 
ID" name="userid" id="userid" class="placeHolder" onfocus="if(this.value==defaultValue)
{this.value='';};" size="30" maxlength="264" data-field-placeholder="Email or ID" data
-field-required="1"></td></tr></table></td></tr><tr id="row_password"><td    
align="right">
</td><td>
<table class="fieldLayout"><tr><td><input type="password"
value="Password" name="password" id="password" class="placeHolder" 
onfocus="if(this.value==defaultValue){this.value='';};" size="30" maxlength="12" data-
field-placeholder="Password" data-field-required="1"></td></tr></table></td></tr><tr>   
<td>
<!--label column--></td><td colspan="5"><input type="submit" id="submitButton"  
value="Sign
In" class="formButton" om-event="User Utilities|Sign In - Member|Sign In"></td></tr>
</table><!--end FORM table-->
</form>

所以似乎相关的字段是用户名和密码

So it seems the relevant fields are userid and Password

推荐答案

您发布了错误的表单数据.

You posted wrong form data.

查看帖子数据:

所以帖子数据可能看起来像这样:

So the post data may look like this:

payload = {  
   'dummy::login_form': 1,  
   'form::login_form': 'login_form',  
   'xurl': '/',  
   'master_product': 150,  
   'vendor': 'cbssports',  
   'userid': YOUR EMAIL HERE,  
   'password': YOUR PASSWORD HERE,  
}

这篇关于使用Python请求传递登录名/密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆