如何在Python的登录页面中发送post请求?

2024-09-24 02:27:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在请求登录页面的帖子中遇到了问题,我看到了它的登录表单,但仍然无法让它工作

我试着用其他URL发帖请求它,我试着用session,用header,但没有任何效果

这是html代码表单:

<form id="loginForm" name="logon" action="//my.yad2.co.il/newOrder/index.php?action=connect" method="POST" style="padding-top:10px;" autocomplete="off">
                                        <input type="hidden" name="nextPage" value="https://my.yad2.co.il/newOrder/index.php?action=personalAreaIndex" />
                                    <table>
                    <tr>
                        <td style="padding-bottom:7px; padding-right:24px;">

                            <input type="text" name="UserName" id="userName" value="" placeholder="שם משתמש"><br>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-right:24px;">
                            <input type="password" name="password" id="password" value="" placeholder="סיסמה"><br>
                        </td>
                    </tr>
                                            <tr class="row errors">
                                                    <td colspan="2" class="error">
                            <label class="login" for="password">שם המשתמש או הסיסמא שהזנת אינם נכונים</label>
                    </tr>
                                    <tr>
            <td class="submitLogonFormTd">
                <input type="submit" id="submitLogonForm" value="">
            </td>
        </tr>
            </table>

 </form>

这就是我尝试的(Python): 导入请求

payload = {
'UserName' : 'email@gmail.com',
'password' : 'mypass'
} 

url = 'https://my.yad2.co.il/newOrder/index.php?action=connect'
with requests.Session() as s:
    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.text)

不知何故,当我查看服务器返回的html代码时,我收到的电子邮件或密码是不正确的,尽管它们不是

以下是“网络”选项卡的图像: enter image description here


Tags: nameidinputvaluemyhtmltypeaction