Jsoup登录Moody's [英] Jsoup login to Moody's

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

问题描述

我尝试使用Jsoup登录Moody的网站时遇到问题。

I have problem when trying to login to Moody's website using Jsoup. I had no problems with other sites, but the way I login in other cases doesn't work for Moodys.

这是我的代码:

Response initialResponse = Jsoup.connect("https://www.moodys.com/login.aspx")
                                .execute();

Response loginResponse = Jsoup.connect("https://www.moodys.com/login.aspx")
                    .cookies(initialResponse.cookies())
                    .data("MdcUserName", "username")
                    .data("MdcPassword", "password")
                    .method(Method.POST).execute();

doc = Jsoup.connect("any other moody's page")
                    .cookies(loginResponse.cookies())
                    .timeout(3000000).get();

System.out.printl(doc.html());

但这不起作用。我做错了什么?谢谢。

But this does not work. What am I doing wrong? Thank you.

推荐答案

基本上,您的代码在urls和post参数中失败。

Basically, your code was failing in the urls and post parameters.

这是一个工作示例:

public static void main(String[] args) {
        try
        {
            Response initialResponse;

            initialResponse = Jsoup.connect("https://www.moodys.com/")
                    .execute();

            Response loginResponse = Jsoup
                    .connect("https://www.moodys.com/identity/login")
                    .cookies(initialResponse.cookies())
                    .data("UserName", "--")
                    .data("Password", "--")
                    .data("IsRememberMe", "false")
                                    .method(Method.POST)
                    .execute();
                    //example of internal moody's page.
            Document doc = Jsoup
                    .connect(
                            "https://www.moodys.com/newsandevents/events_/-/-/2/0/elq")
                    .cookies(loginResponse.cookies()).timeout(3000000).get();

                    //simple div selection example
            System.out
                    .println(doc
                            .select("#ctl00_ctl00_MdcWebPartManager_EventsListWebPart_ctl00_ctl00_NoRecordTipsLabel"));
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

输出:

<span id="ctl00_ctl00_MdcWebPartManager_EventsListWebPart_ctl00_ctl00_NoRecordTipsLabel">You have not registered for any upcoming event(s).</span>

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

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