0

我有一个问题:我无法使用 Jsoup 登录 Betfair 页面似乎没问题,但没有得到登录页面的返回 :(

// 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);

谁能帮我?

4

3 回答 3

2

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

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,你需要填写它

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

现在你只需要很好地在文档中标记你需要它来从中获取数据

System.out.println(doc.body().text());
于 2014-01-20T09:34:16.683 回答
2

您必须连接到登录页面并将其 cookie 用于 post 命令。像这样的东西:

    Connection.Response response1 = Jsoup.connect("https://lite.betfair.com/Login.do?s=000009z-redirectDefault")
            .execute();
    Map<String, String> cookies = response1.cookies();

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

    for (Entry<String, String> cookie : cookies.entrySet()) {
        connection2.cookie(cookie.getKey(), cookie.getValue());
    }
    Response response2 = connection2.execute();
    cookies.putAll(response2.cookies());

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

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

我顺便使用了你的代码来连接另一个页面,它第一次工作。所以你帮助了我,我试着帮助你。:)

于 2013-10-04T13:34:02.247 回答
0

注意:网站的会话名称,您可以这样知道:登录到您的网站,您需要知道会话名称或 cookie 然后登录后在 URL 字段中写入此命令

javascript:void(alert(document.cookie))

然后获取会话名称

于 2014-01-20T10:29:30.237 回答