使用JSoup登录Linkedin [英] Login into Linkedin with JSoup

查看:86
本文介绍了使用JSoup登录Linkedin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最好使用Jsoup登录Linkedin.

I need to login into Linkedin with Jsoup, preferably.

这是我用来登录另一个网站的内容,但不适用于Linkedin.

This is what I'm using to login to another website but it isn't working for 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.

I need to be able to fetch user profiles by using a web crawler but whatever I try I can't get the login cookies.

推荐答案

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

You can login into Linkedin with this code:

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

这篇关于使用JSoup登录Linkedin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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