使用HtmlUnit登录到LinkedIn,然后导航到Connections网页 [英] Login to LinkedIn using HtmlUnit and navigate to Connections Web page

查看:77
本文介绍了使用HtmlUnit登录到LinkedIn,然后导航到Connections网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在尝试使用HtmlUnit 2.20登录到LinkedIn.但是我无法登录.下面是我的代码.

Currently I am trying to login to LinkedIn using HtmlUnit 2.20. But I am not able to login. Below is my code.

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();
        } 

    }

您能否协助找到我的代码有什么问题以及登录后如何导航到另一个页面.

Could you please assist in finding what is wrong with my code and how do I navigate to another page after I login.

推荐答案

尝试一下...

在这里我找到了用于登录Linkedin的解决方案...

Here i found solution for linkedin login......

   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();
    }

这篇关于使用HtmlUnit登录到LinkedIn,然后导航到Connections网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆