如何在没有动作的情况下发送表单的发布请求

时间:2017-08-21 03:11:25

标签: php python html web-scraping http-post

所以我试图在python中使用我的代码登录Spotify,但问题是我无法找到我应该发布请求的网址,因为表单中没有动作属性。 login url

这是表单代码:

  <form _lpchecked="1" class="ng-valid-sp-disallow-chars ng-dirty ng-valid-parse ng-valid ng-valid-required" name="$parent.accounts" ng-submit="submit(form)" novalidate="">
   <!-- ngIf: status && status !== 200 -->
   <div class="row" ng-class="{'has-error': (accounts.username.$dirty &amp;&amp; accounts.username.$invalid)}">
    <div class="col-xs-12">
     <label class="control-label sr-only ng-binding" for="login-username">
      Username or email address
     </label>
     <input autocapitalize="off" autocomplete="off" autocorrect="off" autofocus="autofocus" class="form-control input-with-feedback ng-pristine ng-untouched ng-valid ng-valid-sp-disallow-chars ng-not-empty ng-valid-required" id="login-username" name="username" ng-model="form.username" ng-trim="false" placeholder="Username or email address" required="" sp-disallow-chars=":%&amp;'`´&quot;" sp-disallow-chars-model="usernameDisallowedChars" style='background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAASCAYAAABSO15qAAAAAXNSR0IArs4c6QAAAUBJREFUOBGVVE2ORUAQLvIS4gwzEysHkHgnkMiEc4zEJXCMNwtWTmDh3UGcYoaFhZUFCzFVnu4wIaiE+vvq6+6qTgthGH6O4/jA7x1OiCAIPwj7CoLgSXDxSjEVzAt9k01CBKdWfsFf/2WNuEwc2YqigKZpK9glAlVVwTTNbQJZlnlCkiTAZnF/mePB2biRdhwHdF2HJEmgaRrwPA+qqoI4jle5/8XkXzrCFoHg+/5ICdpm13UTho7Q9/0WnsfwiL/ouHwHrJgQR8WEwVG+oXpMPaDAkdzvd7AsC8qyhCiKJjiRnCKwbRsMw9hcQ5zv9maSBeu6hjRNYRgGFuKaCNwjkjzPoSiK1d1gDDecQobOBwswzabD/D3Np7AHOIrvNpHmPI+Kc2RZBm3bcp8wuwSIot7QQ0PznoR6wYSK0Xb/AGVLcWwc7Ng3AAAAAElFTkSuQmCC"); background-repeat: no-repeat; background-attachment: scroll; background-size: 16px 18px; background-position: 98% 50%; cursor: auto;' type="text"/>
     <!-- ngIf: accounts.username.$dirty && accounts.username.$invalid -->
    </div>
   </div>
   <div class="row" ng-class="{'has-error': (accounts.password.$dirty &amp;&amp; accounts.password.$invalid)}">
    <div class="col-xs-12">
     <label class="control-label sr-only ng-binding" for="login-password">
      Password
     </label>
     <input autocomplete="off" class="form-control input-with-feedback ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" id="login-password" name="password" ng-model="form.password" ng-trim="false" placeholder="Password" required="" style='background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAASCAYAAABSO15qAAAAAXNSR0IArs4c6QAAAUBJREFUOBGVVE2ORUAQLvIS4gwzEysHkHgnkMiEc4zEJXCMNwtWTmDh3UGcYoaFhZUFCzFVnu4wIaiE+vvq6+6qTgthGH6O4/jA7x1OiCAIPwj7CoLgSXDxSjEVzAt9k01CBKdWfsFf/2WNuEwc2YqigKZpK9glAlVVwTTNbQJZlnlCkiTAZnF/mePB2biRdhwHdF2HJEmgaRrwPA+qqoI4jle5/8XkXzrCFoHg+/5ICdpm13UTho7Q9/0WnsfwiL/ouHwHrJgQR8WEwVG+oXpMPaDAkdzvd7AsC8qyhCiKJjiRnCKwbRsMw9hcQ5zv9maSBeu6hjRNYRgGFuKaCNwjkjzPoSiK1d1gDDecQobOBwswzabD/D3Np7AHOIrvNpHmPI+Kc2RZBm3bcp8wuwSIot7QQ0PznoR6wYSK0Xb/AGVLcWwc7Ng3AAAAAElFTkSuQmCC"); background-repeat: no-repeat; background-attachment: scroll; background-size: 16px 18px; background-position: 98% 50%; cursor: auto;' type="password"/>
     <!-- ngIf: accounts.password.$dirty && accounts.password.$invalid -->
    </div>
   </div>
   <div class="row row-submit">
    <div class="col-xs-12 col-sm-6">
     <div class="checkbox">
      <label class="ng-binding">
       <input class="ng-pristine ng-untouched ng-valid ng-not-empty" id="login-remember" name="remember" ng-model="form.remember" type="checkbox"/>
       Remember me
       <span class="control-indicator">
       </span>
      </label>
     </div>
    </div>
    <div class="col-xs-12 col-sm-6">
     <button class="btn btn-sm btn-block btn-green ng-binding">
      Log In
     </button>
    </div>
   </div>
  </form>

2 个答案:

答案 0 :(得分:0)

你可以使用$ .ajax方法在没有操作的情况下发布值。

答案 1 :(得分:0)

请检查并使用:

 <form id="contactForm1" action="/your_url" method="post">
<!-- Form input fields here (do not forget your name attributes). -->
</form>

 <script type="text/javascript">
var frm = $('#contactForm1');

frm.submit(function (e) {

    e.preventDefault();

    $.ajax({
        type: frm.attr('method'),
        url: frm.attr('action'),
        data: frm.serialize(),
        success: function (data) {
            console.log('Submission was successful.');
            console.log(data);
        },
        error: function (data) {
            console.log('An error occurred.');
            console.log(data);
        },
    });
});