Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未能使用python'登录网站;s请求库_Python_Login_Python Requests - Fatal编程技术网

未能使用python'登录网站;s请求库

未能使用python'登录网站;s请求库,python,login,python-requests,Python,Login,Python Requests,编辑我认为问题在于,首次打开网站时,您必须单击“我们的隐私政策已更新…”接受按钮。我现在正在研究如何使用python请求“单击”这个按钮,但是该按钮调用javascript函数,因此我不确定是否可以只使用请求库 我正在尝试为此网站编写脚本: 我需要登录才能执行任务,但登录时遇到问题 我觉得我已经解释了所有正确的参数。我使用regex动态获取csrf_令牌。也许我需要对饼干做点什么,但我不确定是什么 这是我第一次尝试编写一个与网站交互的脚本,如果我太天真,我很抱歉 如果有任何见解,我都会很感激,这

编辑我认为问题在于,首次打开网站时,您必须单击“我们的隐私政策已更新…”接受按钮。我现在正在研究如何使用python请求“单击”这个按钮,但是该按钮调用javascript函数,因此我不确定是否可以只使用请求库

我正在尝试为此网站编写脚本:

我需要登录才能执行任务,但登录时遇到问题

我觉得我已经解释了所有正确的参数。我使用regex动态获取csrf_令牌。也许我需要对饼干做点什么,但我不确定是什么

这是我第一次尝试编写一个与网站交互的脚本,如果我太天真,我很抱歉

如果有任何见解,我都会很感激,这些见解并不仅仅是伪装地告诉我自己愚蠢和/或懒惰

以下是我目前的代码:

import requests;
import re;

payload = {
    'csrf_token': '',
    'email': 'myemail',
    'password': 'mypassword',
    'submit': 'Login'
}

url = 'https://rocket-league.com/login'

with requests.Session() as s:
    r = s.get(url)

    m = re.search("<input type='hidden' name='csrf_token' value='(.+)'", r.text)
    if m: payload['csrf_token'] = m.group(1)
    else: print("couldnt find csrf_token")

    p = s.post('https://rocket-league.com/functions/login.php', data=payload)
    print(p.text)
曲奇饼:

__cfduid: d2c83b2c9ad728195366656a56592f6d71549577451
acceptedPrivacyPolicy: 2.0
euconsent: BObnsHAObnsHAABABAENCF-AAAAkF7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_tphPhA
fantasy_rlcs_id: hA8fga9ghIgaFGA9
PHPSESSID: lrse3tgov95eg574sqga6la9jc
参数:

csrf_token: 3f2588113e8921f52dc3eb78e51246a1
email: myemail
password: mypassword
submit: Login
以下是登录表单的实际HTML:

<form class="rlg-form" method="post" action="/functions/login.php">
<input type="hidden" name="csrf_token" value="3accad82ad0957cab634f805a7e28beb">
<input class="rlg-input" type="email" name="email" placeholder="Email" required="">
<input class="rlg-input" type="password" name="password" placeholder="Password" autocomplete="off" required="">
<fieldset class="rlg-checkbox">
<input type="checkbox" name="rememberme" id="rememberme-login">
<label for="rememberme-login">Remember me?</label>
</fieldset>
<input class="rlg-btn-primary" type="submit" name="submit" value="Login">
</form>

还记得我吗?
<form class="rlg-form" method="post" action="/functions/login.php">
<input type="hidden" name="csrf_token" value="3accad82ad0957cab634f805a7e28beb">
<input class="rlg-input" type="email" name="email" placeholder="Email" required="">
<input class="rlg-input" type="password" name="password" placeholder="Password" autocomplete="off" required="">
<fieldset class="rlg-checkbox">
<input type="checkbox" name="rememberme" id="rememberme-login">
<label for="rememberme-login">Remember me?</label>
</fieldset>
<input class="rlg-btn-primary" type="submit" name="submit" value="Login">
</form>