jsoup 웹 데이터 추출
2929 단어 Android 학습 의 길
가 져 오기 의존:
compile ‘org.jsoup:jsoup:1.10.3’
\ # \ # \ # JSoup 으로 과일 껍질 망 분석 - > 그룹의 데이터
//http://www.guokr.com/group/
Document document = Jsoup.connect("http://www.guokr.com/group/").get();
//System.out.println(document);
Log.e(TAG, "parsingGuoKr: " + document.title());//
// class
Elements titles = document.getElementsByClass("titles");
// titles
Element l1 = titles.first();
// li
Elements li = titles.first().getElementsByTag("li");// li
for (Element e : li) {
// title-link ,
Element elementsByClass = e.getElementsByClass("title-link").first();
...
...
// a
Element titleA = elementsByClass.after("a");
System.out.println(" " + titleA.text());
System.out.println(" " + titleA.attr("href"));
}
...
Elements title_imgs = e.getElementsByClass("title-imgs");
for (Element imgs:title_imgs) {
Elements title_img = imgs.getElementsByClass("title-img");
Elements a = title_img.after("a");
for (Element ima : a) {
String aStr = ima.toString();
int i1 = aStr.indexOf("(");
int i2 = aStr.indexOf(")");
System.out.println(aStr.substring(i1+1,i2));
}
}
\ # \ # \ # 문자열 형식 Html 데 이 터 를 직접 분석 합 니 다.
final TextView tv = (TextView) findViewById(R.id.tv);
Document document = Jsoup.connect("http://www.guokr.com/post/794784/").get();
Element gbbcode_content = document.getElementsByClass("gbbcode-content").first();
final String pStr = gbbcode_content.getElementsByTag("p").toString();
System.out.println(pStr);
runOnUiThread(new Runnable() {
@Override
public void run() {
tv.setText(Html.fromHtml(pStr));
}
});