Ejemplo n.º 1
0
  @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;
  }
Ejemplo n.º 2
0
  private boolean Connect(String Address) {

    for (int Retry = 0; (doc == null) && (Retry < Res.getRetrytimes()); Retry++) {
      try {

        doc = Jsoup.connect(Address).userAgent("Mozilla").timeout(Res.geTimeOut()).get();

      } catch (IOException e) {

        Log.print("FetchCnblogs::Connect", Res.getConRetryMsg() + "第" + (Retry + 1) + "次");
      }
    }

    if (doc == null) return false;
    else return true;
  }
Ejemplo n.º 3
0
  /** 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());
    }
  }