Java 使用HtmlUnit登录LinkedIn并导航到Connections网页
目前我正在尝试使用HtmlUnit 2.20登录LinkedIn。但我无法登录。下面是我的代码Java 使用HtmlUnit登录LinkedIn并导航到Connections网页,java,linkedin,htmlunit,Java,Linkedin,Htmlunit,目前我正在尝试使用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
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();
}
您是否尝试过
webClient.setAjaxController(新的NicelyResynchronizingAjaxController())代码>?我尝试了“webClient.setAjaxController(新的NicelyResynchronizingAjaxController())”。但是我不能登录。