안녕하세요. 파싱관련 질문입니다.
Github 사이트에서 이슈게시판의 제목과 제목을 클릭했을 때 내용을 이런식으로 리스트뷰로 파싱을 하고 싶은데요.
(이슈의 제목을 파싱해서 리스트뷰로)
(파싱한 제목을 클릭했을 때 상세페이지에는 제목과 내용)
제가
이 사이트를 통해 예제를 봤는데 특히 아래 코드 부분에서 어떻게 적용해야할지를 잘 모르겠어요. Github 이슈 게시판에서 제가 원하는 title까지 depth가 아래처럼 10개 정도 되는데... 얘네들을 전부 다 고려해줘야 하나요? 아니면 더 쉽게 하는 방법이 있을까요?
- wrapper
- site
- container
- repository-with-sidebar repo-container new-discussion-timeline
- repository-content context-loader-container
- issues-listing
- table-list table-list-bordered table-list-issues js-navigation-container js-active-navigation-container
- read table-list-item js-navigation-item js-issue-row
- table-list-cell issue-title
- issue-title-link js-navigation-open
여기 보시면 for문으로 계속 돌리던데 10개 depth에 대해서 모두 for문을 돌려야 할까요 ㅠㅠ?
아시는 분들 답변좀 부탁드립니다. 감사합니다.
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
try {
// Connect to the Website URL
Document doc = Jsoup.connect(url).get();
// Identify Table Class "worldpopulation"
for (Element table : doc.select("table[class=worldpopulation]")) {
// Identify all the table row's(tr)
for (Element row : table.select("tr:gt(0)")) {
HashMap<String, String> map = new HashMap<String, String>();
// Identify all the table cell's(td)
Elements tds = row.select("td");
// Identify all img src's
Elements imgSrc = row.select("img[src]");
// Get only src from img src
String imgSrcStr = imgSrc.attr("src");
// Retrive Jsoup Elements
// Get the first td
map.put("rank", tds.get(0).text());
// Get the second td
map.put("country", tds.get(1).text());
// Get the third td
map.put("population", tds.get(2).text());
// Get the image src links
map.put("flag", imgSrcStr);
// Set all extracted Jsoup Elements into the array
arraylist.add(map);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}