当前位置: 首页 > 面试题库 >

使用JSOUP登录到ConEd网站

夹谷岳
2023-03-14
问题内容

我已经广泛阅读了有关此操作的信息,并尝试了许多不同的版本,但无法使其正常工作。

基本上,我只想登录ConEdison网站并抓取我的帐单记录。这是我所拥有的:

Connection.Response loginForm = Jsoup.connect("https://apps.coned.com/cemyaccount/NonMemberPages/Login.aspx?lang=eng")
                    .data("_LASTFOCUS","")
                    .data("_EVENTTARGET","")
                    .data("_EVENTARGUMENT","")
                    .data("_VIEWSTATE", viewState)
                    .data("_EVENTVALIDATION", eventValidation)
                    .data("ctl00$Main$Login1$UserName", username)
                    .data("ctl00$Main$Login1$Password", password)
                    .data("ctl00$Main$Login1$LoginButton", "Sign In")
                    .userAgent("Mozilla/5.0")
                    .method(Method.POST)
                    .execute();

            Map<String, String> loginCookies = loginForm.cookies();

            Document document = Jsoup.connect("https://apps.coned.com/CEMyAccount/CSOL/BillHistory.aspx?lang=eng")
                    .cookies(loginCookies)
                    .get();

            Elements data = document.select("table.ctl00_Main_lvBillHistory_Table1");

            //checking if it found the right page
            System.out.println("document: " + document);
            //checking if it found the table
            System.out.println("data: " + data);

我知道该信息是正确的(尽管我不知道是否真的需要传递没有值的数据参数)。

我没有任何错误,只是打印了登录页面(https://apps.coned.com/cemyaccount/NonMemberPages/Login.aspx?lang=eng)

任何帮助将不胜感激。

谢谢

编辑

因此,我现在确信我无法进入内部页面,因为在POST到https://apps.coned.com/cemyaccount/NonMemberPages/Login.aspx?lang=eng后,设置了3个cookie,但随后它将GET请求发送到https://apps.coned.com/cemyaccount/SessionTransfer.aspx?dir=2asp&url=https://apps.coned.com/csol/MainHome.asp?src=DOTNET,然后发送到https:
//apps.coned.com/csol/SessionTransfer.asp?dir=2asp&guid=3c413f48-d2eb-434a-896b-f9c4eb100714&url=https://apps.coned.com/csol/MainHome.asp?src=DOTNET&frm=
附加前往首页之前的Cookie

有谁知道我如何遵循所有这些重定向并最终获得cookie?

这是我目前拥有的,但是我无法从POST调用中获取Cookie。

Response response = Jsoup
                        .connect("https://apps.coned.com/cemyaccount/NonMemberPages/Login.aspx?lang=eng")
                        .method(Method.GET)
                        .execute();

                Map<String, String> cookies = response.cookies();
                cookies.put("NSC_DpoFe_Bqqt-TTM-pme", response.cookie("NSC_DpoFe_Bqqt-TTM-ofx"));
                System.out.println("response cookies: " + cookies);

                response = Jsoup
                        .connect("https://apps.coned.com/cemyaccount/NonMemberPages/Login.aspx?lang=eng")
                        .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
                        .header("Accept-Encoding", "gzip, deflate")
                        .header("Accept-Language", "en-US,en;q=0.8")
                        .header("Connection", "keep-alive")
                        .cookies(cookies)
                        .header("Host", "apps.coned.com")
                        .referrer("https://apps.coned.com/cemyaccount/NonMemberPages/Login.aspx?lang=eng&login=0")
                        .userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36")
                        .data("_LASTFOCUS", "")
                        .data("_EVENTTARGET", "")
                        .data("_EVENTARGUMENT", "")
                        .data("_VIEWSTATE", viewState)
                        .data("_EVENTVALIDATION", eventValidation)
                        .data("ctl00$Main$Login1$UserName", username)
                        .data("ctl00$Main$Login1$Password", password)
                        .data("ctl00$Main$Login1$LoginButton", "Sign In")
                        .followRedirects(false)
                        .method(Method.POST)
                        .execute();

                System.out.println("post cookies: " + response.cookies());
                cookies.putAll(response.cookies());
                System.out.println("response cookies: " + cookies);

                response = Jsoup
                        .connect("https://apps.coned.com/cemyaccount/SessionTransfer.aspx?dir=2asp&url=https:"
                                + "//apps.coned.com/csol/MainHome.asp?src=DOTNET")
                        .cookies(cookies)
                        .followRedirects(false)
                        .method(Method.GET)
                        .execute();

                cookies.putAll(response.cookies());
                System.out.println("response cookies: " + cookies);
                String guid = response.header("location");

                response = Jsoup
                        .connect("https://apps.coned.com/csol/SessionTransfer.asp?dir=2asp&guid="
                                + guid + "&url=https://apps.coned.com/csol/MainHome.asp"
                                + "?src=DOTNET&frm=")
                        .cookies(cookies)
                        .method(Method.GET)
                        .execute();

                cookies.putAll(response.cookies());
                System.out.println("response cookies: " + cookies);

                Document dataPage = Jsoup
                        .connect("https://apps.coned.com/CEMyAccount/CSOL/BillHistory.aspx?lang=eng")
                        .cookies(cookies)
                        .get();

                System.out.println("data page: " + dataPage);

                Elements data = dataPage.select("table.ctl00_Main_lvBillHistory_Table1");

                System.out.println("data: " + data);

在输出中,我获得了所有cookie,但POST cookie是空白的。


问题答案:

答案非常简单-带下划线的标头有2个下划线,我只使用了1。



 类似资料:
  • 问题内容: 在此网站上,您可以输入您的学生卡号,然后显示该卡上还剩多少钱。我想使用JSOUP获得信息。这是我当前的代码,但是不起作用, 我没有太多经验,所以我不知道在哪里寻找问题。一些想法: 我应该使用还是? 在使用chrome devoloper工具时,发布数据是我使用功能发送的所有数据。但是,如果发送时出现错误,为什么? 我应该发送解密或加密的数据吗?(两者均在chrome devoloper

  • 我试图登录使用领英J汤,我已经尝试了几种方法,但总是遇到错误403,我哪里出错了? 测试一 错误控制台 组织。jsoup。HttpStatusException:获取URL时发生HTTP错误。状态=403,URL=https://www.linkedin.com在org。jsoup。帮手HttpConnection$响应。在org上执行(HttpConnection.java:590)。jsoup

  • 问题内容: 使用Jsoup登录网站需要什么?我相信我的代码是正确的,但是我从未使用Jsoup成功登录到网站,因此我可能会丢失一些东西。这是我的代码: 返回一个显示未成功登录的登录页面。有一个名为的输入值,我认为这可能是为什么它不起作用的原因。这个值会随着时间的推移而上升。我运行了两次代码,时间变量返回了和。我的代码需要大约10秒钟的时间来打印文档,因此,变量在发送发布请求时是否已经更改?我不确定这

  • 问题内容: 如何通过jsoup登录? 我试过了,但是不起作用: 问题答案: 通常,登录网站需要两个步骤- 您发送请求以获取页面,然后从中提取一些值,例如会话ID等以及cookie。 您发送带有第1步中的值以及您的用户名和密码的请求。 要知道您需要发送哪些值,请在开发人员模式下使用浏览器(按F12键)并检查流量。更改字符串以匹配您的浏览器,因为某些站点将不同的页面发送到不同的客户端。

  • 我正在尝试使用jsoup登录一个网站,我很确定我正在解析所有需要解析的东西,我只是不知道出了什么问题。 我用这个做参考:http://cs.harding.edu/fmccown/android/Logging-into-Pipeline.pdf 以下是我的AsycntTask doInBackground中的代码: 但问题是,当我登录时,它不包含页面的文档,它包含一个错误页面的文档,该页面只显示

  • 阅读了一些例子后,我想实现一个爬虫的帮助转移与登录,如: https://target.helpshift.com/login/?next=/admin/issues/ 但是,我得到这个错误: 线程“main”组织中出现异常。jsoup。HttpStatusException:获取URL时发生HTTP错误。状态=403,URL=https://target.helpshift.com/login/