2016-07-13 22 views
0

私はlinkedin Jsoupを使用してログインしようとしていますが、いくつかの方法を試しましたが、常にエラー403に遭遇します。Jsoup - Javaを使用してウェブサイトにログイン

テストの一つ

Connection.Response loginForm = Jsoup.connect("https://www.linkedin.com") 
         .method(Connection.Method.GET) 
         .execute(); 

       Document document = Jsoup.connect("https://www.linkedin.com") 
         .data("login-email", "email") 
         .data("login-password", "password") 
         .cookies(loginForm.cookies()) 
         .post(); 

       System.out.println(document.body().html()); 

//after you logged in go to this page 
Document pesquisa=Jsoup.connect("https://www.linkedin.com/vsearch/p?locationType=Y&f_N=S%2CO&f_G=br%3A6368&f_I=137&trk=vsrp_savedsearch").get(); 

エロコンソール

org.jsoup.HttpStatusException:HTTPエラーURLを取り出します。 org.jsoup.helper.HttpConnection $ Response.executeで org.jsoup.helper.HttpConnection $ Response.execute(HttpConnection.java:590) でステータス= 403、 URL = https://www.linkedin.com(HttpConnection.java:540) org.jsoup.helper.HttpConnection.execute(HttpConnection.java:227) org.jsoup.helper.HttpConnection.post(HttpConnection.java:222)at linkedin.page.main(page.java:27)

HTMLページ・

<form class="login-form" action="https://www.linkedin.com/uas/login-submit" method="POST" data-autologin="true"> 
<label for="login-email">E-mail</label> 
<input type="text" name="session_key" id="login-email" placeholder="E-mail ou número de telefone" autofocus="autofocus"> 
<label for="login-password">Senha</label><input type="password" name="session_password" id="login-password" aria-required="true" placeholder="Senha"> 
<input name="isJsEnabled" type="hidden" value="false"> 
<input name="loginCsrfParam" id="loginCsrfParam-login" type="hidden" value="1802cd0f-af50-45b8-810c-2ecc3bac3c72"> 
<input name="trk" id="trk-login" type="hidden" value="nav_responsive_tab_home"> 
<input name="sourceAlias" id="sourceAlias-login" type="hidden" value="0_7r5yezRXCiA_H0CRD8sf6DhOjTKUNps5xGTqeX8EEoi"> 
<input type="submit" name="submit" value="Entrar"> 
</form> 

login

答えて

0

私は、もう少しコードで、はるかに速く、このように決めたが、うまく自己主張

try { 

      String url = "https://www.linkedin.com/uas/login?goback=&trk=hb_signin"; 
      Connection.Response response = Jsoup 
        .connect(url) 
        .method(Connection.Method.GET) 
        .execute(); 

      Document responseDocument = response.parse(); 
      Element loginCsrfParam = responseDocument 
        .select("input[name=loginCsrfParam]") 
        .first(); 

      response = Jsoup.connect("https://www.linkedin.com/uas/login-submit") 
        .cookies(response.cookies()) 
        .data("loginCsrfParam", loginCsrfParam.attr("value")) 
        .data("session_key", "email") 
        .data("session_password", "password") 
        .method(Connection.Method.POST) 
        .followRedirects(true) 
        .execute(); 

      Document document = response.parse(); 

      System.out.println("Welcome " 
        + document.select(".act-set-name-split-link").html()); 


     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
関連する問題