Jsoup Cookies for HTTPS scraping

后端 未结 3 1047
不知归路
不知归路 2020-11-27 12:41

I am experimenting with this site to gather my username on the welcome page to learn Jsoup and Android. Using the following code

Connection.Response res = J         


        
3条回答
  •  攒了一身酷
    2020-11-27 13:28

    I know I'm kinda late by 10 months here. But a good option using Jsoup is to use this easy peasy piece of code:

    //This will get you the response.
    Response res = Jsoup
        .connect("url")
        .data("loginField", "login@login.com", "passField", "pass1234")
        .method(Method.POST)
        .execute();
    
    //This will get you cookies
    Map cookies = res.cookies();
    
    //And this is the easieste way I've found to remain in session
    Documente doc = Jsoup.connect("url").cookies(cookies).get();
    

    Though I'm still having trouble connection to SOME websites, I connect to a whole lot of them with the same basic piece of code. Oh, and before I forget.. What I figured my problem is, is SSL certificates. You have to properly manage them in a way I still haven't quite figured out.

提交回复
热议问题