Notice
Recent Posts
Recent Comments
꿈소년의 개발 이야기
Jsoup & encoding & charset & html 본문
반응형
how to encoding html using Jsoup in android.
1. request html
1 2 3 4 5 6 7 8 9 | OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(scrapUrl) .header(HEADER_AGENT, USER_AGENT_CHROME) .build(); Response response = client.newCall(request).execute(); htmlBody = response.body().byteStream(); | cs |
2. get Document & extract elements
1 2 | Document doc = Jsoup.parse(htmlBody, null, url); Elements elements = doc.select("meta[property^=og:]"); | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | if (elements != null) { for (Element element : elements) { String property = element.attr("property"); String content = element.attr("content"); switch (property) { case "og:title": og.setTitle(content); break; ..... default: break; } } } | cs |
end.
'Android Development' 카테고리의 다른 글
| Android java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 3(offset:3).state:4 android.support.v7.widget.RecyclerView (0) | 2018.11.01 |
|---|---|
| Vector drawable, error and backward compatibility (0) | 2018.09.12 |
| 페이스북 앱 링크 연결 (link to Facebook app if installed in device) (0) | 2018.01.05 |
| Span 처리 (0) | 2017.10.19 |
| 네이버 아이디로 로그인이 안될 때 with Proguard 설정 (0) | 2017.08.25 |
