简体   繁体   English

我可以使用java HtmlUnit库从linkedIn中提取信息吗?

[英]Can I extract information from linkedIn using java HtmlUnit library?

I tried hard to find a way to extract data from my LinkedIn account without using the REST API but any result :/ Anyone know if it's possible and how? 我试图找到一种方法从我的LinkedIn帐户中提取数据而不使用REST API但任何结果:/任何人都知道它是否可能以及如何? When I tried this code in Eclipse the result were either a NullPointerException or null when I selected some fields from the response html page. 当我在Eclipse中尝试此代码时,结果是NullPointerException或当我从响应html页面中选择一些字段时为null。 Note that the selector path works well in the console of the browser. 请注意,选择器路径在浏览器的控制台中运行良好。 Thank you very much. 非常感谢你。

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);
HtmlPage loginPage = webClient.getPage(url); 
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("something@outlook.com");
passwordTextField.setValueAttribute("**************");
final HtmlPage response = button.click();
loginPage=webClient.getPage("https://www.linkedin.com/in/issa-hammoud-
0a2802114/");
System.out.println(loginPage.querySelector("#profile-wrapper > div.pv-
content.profile-view-grid.neptune-grid.two-column.ghost-animate-in > 
div.core-rail > section div > div > button > img");

Since you are making a secured connection (HTTPS) you need to specify getOptions().setUseInsecureSSL(true); 由于您正在建立安全连接(HTTPS),因此需要指定getOptions().setUseInsecureSSL(true);

Also make sure you enable cookies getCookieManager().setCookiesEnabled(true); 还要确保启用cookie getCookieManager().setCookiesEnabled(true);

Having said that you should really be using the Linkedin's REST API. 说过你应该真的使用Linkedin的REST API。

Hope that helps 希望有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅从根元素中提取文本内容 - java, com.gargoylesoftware.htmlunit.html - How can I extract text content only from root element - java, com.gargoylesoftware.htmlunit.html 如何使用HtmlUnit检查我是否登录了网站(例如LinkedIn)? - How can I check if I logged in a website (e.g. LinkedIn) using HtmlUnit? 在java中如何从图像中提取相机相关信息? - In java how can I extract camera related information from an image? 如何从Java中的txt文件提取以下信息 - How can I extract the following information from a txt file in java 如何在Java中使用Jaunt或Jsoup或HtmlUnit登录linkedIn? - How to login linkedIn using Jaunt or Jsoup or HtmlUnit in java? 如何使用htmlunit从ajax / javascript网站提取数据? 我正在尝试提取运输历史记录 - How to extract data from ajax/javascript websites using htmlunit? I m trying to extract shipment history Java - 如何使用HtmlUnit登录网站? - Java – How can I Log into a Website with HtmlUnit? 我可以在 htmlunit 中获取 JavaScript 函数的信息吗? - Can I get JavaScript function's information in htmlunit? 我可以使用 Java 为 LinkedIn 开发桌面应用程序吗? - Can I develop a Desktop App for LinkedIn using Java? 如何使用 HtmlUnit 从 html 页面中提取元素 - How to extract elements from html page using HtmlUnit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM