2017-08-01 82 views
-2

我一直在試圖登錄到這個頁面https://www.gpro.net/gb/gpro.aspjsoup,我幾乎把我所有的頭髮拉出來,它只是不起作用。如何使用Jsoup在此特定頁面中登錄?

這是我一直想:

Connection.Response loginForm = Jsoup.connect("https://www.gpro.net/gb/gpro.asp") 
      .method(Connection.Method.GET) 
      .execute(); 

      Document document = Jsoup.connect("https://www.gpro.net/gb/gpro.asp") 
      .data("cookieexists", "false") 
      .data("Text1", "myEmail") 
      .data("Password2", "myPassword") 
      .cookies(loginForm.cookies()) 
      .post(); 
      System.out.println(document); 

和這裏的形式

<form method="post" action="Login.asp?Redirect=gpro.asp" ID="Form1" style="margin:0px"> 
     <h1>Quick login</h1> 
     <div class="inner"> 

     <label for="textLogin">Username or Email address:</label> 
     <input type="text" name="textLogin" value="" class="texty" ID="Text1"> 
     <label for="textLogin">Password:</label> 
     <input type="password" name="textPassword" class="texty" ID="Password2"> 
     <input type="hidden" name="token" value="" ID="token"> 
     <input type="hidden" name="Logon" value="Login" ID="Hidden1"> 
     <input type="submit" name="LogonFake" value="Login" class="halo micro" ID="Submit2"> 
     <a href="LostPassword.asp" class="password">Forgotten your password?</a>   
     <div class="center" style="clear:both; float:left; width:100%; text-align:center; margin:-3px 0 11px !important;"> 
      <a class="fb_button fb_button_medium" href="#" onclick="fbLogin()" style="border-radius:6px 6px 6px 6px; display:inlineblock;"> 
       <span style="border-radius:0 6px 6px 0; background-clip: padding-box;" class="fb_button_text">Login with Facebook</span> 
      </a> 
     </div> 
     ... 

誰能給我一隻手,好嗎? 謝謝。

回答

1

您的POST請求參數是錯誤的。 工作代碼:

try { 
     Connection.Response response = Jsoup.connect("http://www.gpro.net/gb/Login.asp?langCode=gb&Redirect=gpro.asp") 
       .method(Connection.Method.POST) 
       .data("textLogin", "") // username 
       .data("textPassword", "") // password 
       .data("Logon", "Login") 
       .execute(); 

     System.out.println(response.body()); 
     System.out.println(response.cookies()); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
+0

非常感謝! – Barbaroto

相關問題