Jsoup无法在页面上登录 [英] Jsoup can't Login on Page

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

问题描述

我有一个问题:我无法使用Jsoup登录必发页面,但似乎无法返回登录页面:(

I have a problem: I can't login on page Betfair with Jsoup seems to be okay but do not get the return of logged page :(

// You can try with this username and password for testing
// Username: <redacted>
// Password: <redacted>
// LoginUrl: lite.betfair.com/Login.do?s=000009z-redirectDefault


// This is my Code 

Connection.Response res = Jsoup.connect("https://lite.betfair.com/SLoginsubmit.do?s=000009z-redirectDefault&secure=true")
                    .data("username", "<redacted>", "password", "<redacted>")
                    .method(Method.POST)
                    .execute();
            Map<String, String> cookies = res.cookies();


            Connection connection = Jsoup.connect("https://lite.betfair.com/Mybets.do?s=000209z");
            for (Entry<String, String> cookie : cookies.entrySet()) {
                connection.cookie(cookie.getKey(), cookie.getValue());
            }


            Document document = connection.get();
            System.out.println(document);

谁可以帮助我?

推荐答案

只需要知道cookie或SessionName的名称,然后就可以使用它登录

just you need to know what is the name of cookies or SessionName then you can use it to login

Response res = Jsoup.connect("https://lite.betfair.com/SLoginsubmit.do?s=000009z-rredirectDefault&secure=true")
                .method(Method.GET)
                .timeout(10000)
                .execute();

        sessionID = res.cookie("JSESSIONID");//her put the SessionName for website 

现在您拥有网站的SessionName,并且需要填写

now you have the SessionName of website and you need to fill it

String username="your username";
String password="your pass";

Jsoup.connect("https://lite.betfair.com/SLoginsubmit.do?s=000009z-redirectDefault&secure=true")
                .data("login:username", username, "login:password", password, "login:loginImg", "", "login", "login")
                .cookie("JSESSIONID", sessionID)
                .method(Method.POST)
                .timeout(10000)
                .execute();// now you have SessionName and you can use it for any page in website


Document doc = Jsoup.connect("https://lite.betfair.com/Mybets.do?s=000209z")
                .cookie("JSESSIONID", sessionID)
                .timeout(10000)
                .get();// her to open any page with SessionName you have it

现在您只需要在文档中标记所需的标签即可从中获取数据

now you just need to good to tag you need it in doc to get your data from it

System.out.println(doc.body().text());

这篇关于Jsoup无法在页面上登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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