JSoup character encoding issue

The charset attribute is missing in HTTP response Content-Type header. Jsoup will resort to platform default charset when parsing the HTML. The Document.OutputSettings#charset() won't work as it's used for presentation only (on html() and text()), not for parsing the data (in other words, it's too late already).

You need to read the URL as InputStream and manually specify the charset in Jsoup#parse() method.

String url = "http://www.latijnengrieks.com/vertaling.php?id=5368";
Document document = Jsoup.parse(new URL(url).openStream(), "ISO-8859-1", url);
Element paragraph = document.select("div.kader p").first();

for (Node node : paragraph.childNodes()) {
    if (node instanceof TextNode) {
        System.out.println(((TextNode) node).text().trim());
    }
}

this results here in

Aeneas dwaalt rond in Troje en zoekt Creüsa.
Creüsa is echter op de vlucht gestorven
Plotseling verschijnt er een schim.
Het is de schim van Creüsa.
De schim zegt:'De oorlog woedt!'
Troje is ingenomen!
Creüsa is gestorven:'Vlucht!'
Aeneas vlucht echter niet.
Dan spreekt de schim:'Vlucht! Er staat jou een nieuw vaderland en een nieuw koninkrijk te wachten.'
Dan pas gehoorzaamt Aeneas en vlucht.

Well, I figured out another way to do that. In my case, I had an Jsoup Connection object and I wanted to retrieve the html response from a post() request in a website that was encoded with "ISO-8859". As the default encoding for JSOUP is UTF-8, the content from the response (the html) was coming with � replacing some letters. I needed to somehow convert it to ISO-8859-15. To perform that, I've created the connection

Connection connectionTest = Jsoup.connect("URL")
.cookie("cookiereference", "cookievalue")
.method(Method.POST);

After that, I've created a response Document that holds the answer of the post. Due to the fact that it was not clear how we can set the encoding of the response in Jsoup, I opted to execute the post and then save the response as Bytes, preserving the encoding properties. After that, I've created a new String passing this Byte array and the proper encoding that must be applied. After that, the document will be created with the correct encoding.

Document response = Jsoup.parse(new String(
connectionTest.execute().bodyAsBytes(),"ISO-8859-15"));

So, there is the return before and after the modification, when we use response.html()

Before:

62.09-1-00 - Suporte t�cnico, manuten��o e outros servi�os em tecnologia da informa��o

After:

62.09-1-00 - Suporte técnico, manutenção e outros serviços em tecnologia da informação