java - 使用 JSoup 登录 Linkedin

标签 java web-crawler jsoup linkedin

我最好使用 Jsoup 登录 Linkedin。

这是我用来登录另一个网站的方法,但它不适用于 Linkedin。

Connection.Response res = Jsoup
    .connect("https://www.linkedin.com/uas/login?goback=&trk=hb_signin")
    .data("session_key", mail, "session_password", password)
    .method(Connection.Method.POST)
    .timeout(60000).

// Also tried "https://www.linkedin.com/uas/login-submit"

Map<String, String> loginCookies = res.cookies();
    //Checking a profile to see if it was succesful or if it returns the login page.    
Document currentPage = Jsoup.connect(someProfileLink).cookies(loginCookies).timeout(10000).
System.out.println("" + currentPage.text());

我做错了什么?

我需要能够使用网络爬虫获取用户配置文件,但无论我尝试什么,我都无法获取登录 cookie。

最佳答案

您可以使用以下代码登录 Linkedin:

    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", "your_login")
                        .data("session_password", "your_password")
                        .method(Connection.Method.POST)
                        .followRedirects(true)
                        .execute();

                Document document = response.parse();

    //            System.out.println(document)

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

            } catch (IOException e) {
                e.printStackTrace();
            }

关于java - 使用 JSoup 登录 Linkedin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31280097/

相关文章:

java - BufferedWriter的优点

python - 当使用Python asyncio corurrent发送网络请求时,如何让协程更喜欢先继续处理响应,而不是发送新的请求?

java - 在什么情况下网络爬虫可能会受到 CPU 限制而不是 IO 限制?

android - 获取第一个元素时奇怪的 jsoup 行为

java - JSOUP 在 Eclipse 中抛出 url 状态 503 但 URL 在浏览器中工作正常

java - 从 MySQL 数据库获取 Java 中的 Sum(total)

java - IntelliJ IDEA - 如何将 .java 文件复制为资源?

java - 检查 Hashmap 中的键是否在 AutoCompleteTextView 中输入

web-scraping - 这种反抓取技术对于 Robots.txt Crawl-Delay 是否可行?

javascript - Android WebView 未返回所需的 HTML