Java中的Jsoup库-登录Google [英] Jsoup library in Java - logging on Google

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

问题描述

问题是我该如何编写代码以仅接收一个cookie,该cookie可用于连接到需要登录的网站?

The question is just how should I write my code to receive just one cookie, which I could use for connecting to websites that require logging in?

Connection.Response res = Jsoup.connect("https://gmail.com")
        .data(<all stuff for logging in>)
        .execute();

res.cookies()会给我我的会话ID等.

And res.cookies() would give me my session ID etc.

推荐答案

我尝试过:

  String loginUrl = "https://accounts.google.com/Login?hl=pl#identifier";
  Connection.Response res = Jsoup.connect(loginUrl)
          .data("Email", MYMAIL)
          .execute();

  Connection.Response res2 = Jsoup.connect(loginUrl)
          .cookies(res.cookies())
          .data("Passwd", MYPASS)
          .execute();


  Document page = Jsoup
            .connect("https://adwords.google.com/")
            .cookies(res2.cookies()) 
            .get();

  System.out.println(page.toString());

我没有看到我想要看到的页面.可能这不应该起作用,但是我还不能编写任何更好的代码.它在t

And I don't see the page I want to see. Propably this shouldn't be working but I can't code anything better yet. It worked on t

基本上,我的主要目标是能够使用Java从AdWords提取数据(我正在使用Eclipse).最后的障碍是登录.

Basically, my main target is to be able to extract data from AdWords using Java (I'm working with Eclipse). The last obstacle is logging in.

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

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