@Override public LinkList<ItemInfo> getItems(int count) { int retry = 0; if (Connect(Res.getBaseAddress())) { parser(); } else { System.out.println(Res.getConFailueMsg()); } while (ItemName.size() < count || retry >= Res.getRetrytimes()) { if (Connect(Res.getFollowingAddress() + pages)) { parser(); pages++; } else retry++; } for (int lp = 0; lp < count; lp++) { ItemInfo aItem = new ItemInfo(); aItem.setItemName(ItemName.get(lp)); aItem.setItemSummery(ItemSummery.get(lp)); aItem.setPostTime(ItemPostTime.get(lp)); aItem.setItemLink(ItemLink.get(lp)); ItemData.add(aItem); } return ItemData; }
/** get post body and fetch the image links */ @Override public void getContent(ItemInfo item) { Document adoc = null; for (int j = 0; adoc == null && j < Res.getRetrytimes(); j++) { System.out.println("Startting fetching contets of" + item.getItemName()); try { adoc = Jsoup.connect(item.getItemLink()).userAgent("Mozilla").timeout(Res.geTimeOut()).get(); } catch (IOException e) { System.out.println(Res.getConRetryMsg()); } } if (adoc == null) { System.out.println("fetch tips error, adoc is null"); item.setContent(Res.getFileNotExistMsg()); } else { item.setContent(adoc.getElementsByClass("post").html()); } }