Question

I log in to the site (I know that because the result of the code shows me I am in: "Dilema Veche Contul meu Logout Întreb?ri frecvente ... etc) successfully but I cannot navigate the links of the website logged in, it seems that doesn't keep the cookies or something. Any suggestions? Thank you.

public class art { public static void main(final String[] args) throws IOException {

Response res = Jsoup.connect("http://pay.dilemaveche.ro/autentificare/?redirect=http%3A%2F%2Fdilemaveche.ro%2F%2F&return=true").data("username", "myusername", "password", "mypassword").method(Method.POST).execute();


Map <String, String> cookies = res.cookies();
Document doc = Jsoup.connect("http://pay.dilemaveche.ro/autentificare/?redirect=http%3A%2F%2Fdilemaveche.ro%2F%2F&return=true").cookies(cookies).get();
Elements bck = doc.select("li.first").select("a[href]:contains(Dilema Veche)");
String str = bck.attr("abs:href");
Document doc0 = Jsoup.connect(str).cookies(cookies).get();
System.out.println(doc.text());
}

}

Was it helpful?

Solution

Logining a website require many steps, and it depends on how the website handling cookie. Most of the big websites now are using custom cookie policy, and Jsoup cookie's handler is very general. I don't think JSoup is a good choice for this, but you can use JSoup to parse the HTML when you have the cookie. I suggest you should try out HttpClient or URLConnection, especially HttpClient . Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top