簡體   English   中英

使用HtmlUnit登錄到LinkedIn,然后導航到Connections網頁

[英]Login to LinkedIn using HtmlUnit and navigate to Connections Web page

目前,我正在嘗試使用HtmlUnit 2.20登錄到LinkedIn。 但是我無法登錄。 下面是我的代碼。

public static void Login(String username, String password) {
         final WebClient webClient = new WebClient(BrowserVersion.CHROME);
        try {

            final HtmlPage page = webClient.getPage "https://www.linkedin.com/secure/login");

            final HtmlForm form = page.getForms().get(0);
            final HtmlSubmitInput button = form.getInputByName("signin");
            final HtmlTextInput emailBtn = form.getInputByName("session_key");
            final HtmlPasswordInput passBtn = form.getInputByName("session_password");

            emailBtn.setValueAttribute(username);
            passBtn.setValueAttribute(password);

            final HtmlPage page2 = button.click();
            System.out.println(page2.getWebResponse().getContentAsString());

        } catch (Exception ex ){
            ex.printStackTrace();
        } 

    }

您能否協助找到我的代碼有什么問題以及登錄后如何導航到另一個頁面。

嘗試這個...

在這里,我找到了用於linkedin登錄的解決方案……

   try {
        String url = "https://www.linkedin.com/uas/login?goback=&trk=hb_signin";
        final WebClient webClient = new WebClient();
        webClient.getOptions().setJavaScriptEnabled(false);
        webClient.getOptions().setCssEnabled(false);

        final HtmlPage loginPage = webClient.getPage(url);
        //Get Form By name 
        final HtmlForm loginForm = loginPage.getFormByName("login");
        final HtmlSubmitInput button = loginForm.getInputByName("signin");
        final HtmlTextInput usernameTextField = loginForm.getInputByName("session_key");
        final HtmlPasswordInput passwordTextField = loginForm.getInputByName("session_password");
        usernameTextField.setValueAttribute(userName);//your Linkedin Username
        passwordTextField.setValueAttribute(password);//Your Linkedin Password
        final HtmlPage responsePage = button.click();
        String htmlBody = responsePage.getWebResponse().getContentAsString();
        System.out.println(htmlBody);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM