请求模块 - 尝试发布

时间:2014-09-13 05:21:40

标签: python html validation post urllib

我正在使用带有python 3.3的请求模块,我正在尝试发布数据。这是我要发布的数据。我已经解析了html中的值:

<form action="/checkoutnow/2" autocomplete="off" class="proceed" id="loginForm" method="post" name="login_form" novalidate="novalidate">
  <input id="loginForm" name="execution" type="hidden" value="e21s1"> <input name="token" type="hidden" value="EC-2MJ027776Y1687721"> <input id="incontext" name="incontext" type="hidden" value="0"> <input id="eventID" name="_eventId_submit" type="hidden">

  <div class="" id="loginFields">
    <div class="inputField emailField confidential">
      <label for="email">Email</label> <input autocomplete="off" data-validate-email="true" id="email" name="email" type="email" value="">

      <div class="tip tipHint">
        <div class="tipArrow tipArrowFront tipHintArrowFront"></div>

        <div class="tipArrow tipArrowBack tipHintArrowBack"></div>

        <ul class="tipText tipHintText">
          <li>Did you mean <a class="emailLink" href=""></a>?
          </li>
        </ul>
      </div>
    </div>

    <div class="inputField passwordField confidential">
      <label for="password">Password</label> <input autocomplete="off" id="password" maxlength="22" name="password" type="password" value="">

      <div class="toolTip tip guestTooltip">
        <div class="tipArrow tipArrowFront tipErrorArrowFront"></div>

        <div class="tipArrow tipArrowBack tipErrorArrowBack"></div>

        <div class="tipText tipErrorText">
          Trouble logging in? You can try again, or <a class='submit' href='/checkoutnow/2?execution=e21s1&_eventId_guest' id='guestTooltipLink'>check out as a guest</a>
        </div>
      </div>
    </div>
  </div>

  <div class="buttons varA">
    <input class="btn full continue" name="_eventId_submit" type="submit" value="Log in to PayPal">

    <div class="forgotPassword secondary" id="forgotPasswordSection">
      <a href='/us/merchantpaymentweb?cmd=_account-recovery&amp;from=PayPal' id='forgotPassword' target='_blank'>Forgot your password?</a>
    </div>
    <hr class="sep">
    <a class="btn btn-secondary submit" href="/checkoutnow/2?execution=e21s1&_eventId_guest&token=EC-2MJ027776Y1687721" id="checkoutAsAGuestBtn">Pay with Debit or Credit Card</a>
  </div>
</form>

这是我的代码来解决这个问题。我正在使用会话btw。

payload6 = {'loginFields': {'password': paypalpass, 'email': useremail}, 'token': token, 'execution': execution, 'incontext': incontext, '_eventId_submit': ''}
r = session.post(urlnow, data=payload6)

我相信我的问题是'loginFields',因为我发布后,值仍为空。

2 个答案:

答案 0 :(得分:0)

您的POST数据不应该有任何嵌套的dicts。 passwordemail应该是tokenexecution之类的顶级密钥,而不是像现在一样嵌套在loginFields下。 (我假设loginFields现在位于您的有效负载中,因为<div id="loginFields">,但是这样的包装器不应该对POST数据的结构有任何影响。)

答案 1 :(得分:0)

事实证明,javascript正在产生更多变量。谢谢你的帮助。