Y
Y
YungSherman2017-09-01 01:18:18
Android
YungSherman, 2017-09-01 01:18:18

How to solve encoding problem in jsoup?

In my application, I parse content from an html page using the jsoup library, the link to this page consists of Russian and Latin characters (Cyrillic characters as a get-request parameter). The problem is that jsoup does not see the Cyrillic part of the link and the content is not parsed. When a full link is displayed in the log, the link is displayed like this: e085387b616c4f2086b6c0b995042216.PNG
I tried to change the encoding of the Cyrillic part using URLEncoder (in utf-8), now percentages and numbers appear instead of Cyrillic. The link in the log opens normally through the computer browser, but parsing still does not occur. I can't figure out what's wrong.

private String mCurrentGroup; 
    private final String mLink = "http://mai.ru/education/schedule/detail.php?group=";
    private String mWeek = "1";
    private final String PLUS_WEEK = "&week=";
    mCurrentGroup = mSharedPreferences.getString(getString(R.string.pref_group), ""); //получаем кириллический параметр get-запроса
//"собираем полную ссылку и меняем кодировку у кириллической части, подключаемся
doc = Jsoup.connect(mLink.concat(URLEncoder.encode(mCurrentGroup, "utf-8")).concat(PLUS_WEEK).concat(mWeek)).get();

The strangest thing. that until some point everything worked fine, even without changing the encoding, that is, the algorithm for getting content from the page is working fine, jsoup cannot connect to the page now.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mr_serg77, 2017-09-01
@mr_serg77

Show mistakes.
Use Retrofit + Scalars converter, from it response body to Jsoup Document or wherever needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question