简体   繁体   中英

Jsoup library in Java - logging on Google

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

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

I tried this:

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM