예제 #1
0
 @Override
 public Elements getElements() {
   Elements elements = new Elements();
   for (XElements xElements : elementsList) {
     elements.addAll(xElements.getElements());
   }
   return elements;
 }
  public List<EntryNews> getEntryNews(String sectionRef) throws IOException {
    String imgRef;
    String newsRef;
    String title;
    String announce;
    String date;
    String url;

    if (!sectionRef.contains("http://ria.ru")) {
      url = "http://ria.ru" + sectionRef;
    } else {
      url = sectionRef;
    }

    List<EntryNews> entryNewsList = new ArrayList<>();

    Document doc = Jsoup.connect(url).userAgent("Mozilla").get();

    Elements entryNewsElements;
    Elements listItems;

    if (sectionRef.contains("religion")) {

      entryNewsElements = doc.select(".rubric_bytheme_item_block_wrap");
      listItems = entryNewsElements.select(".rubric_bytheme_item_block");

      for (Element element : listItems) {
        imgRef = element.select("img").attr("src");
        newsRef = element.select(".rubric_bytheme_item_block_inner.photo a").attr("href");
        title = element.select(".rubric_bytheme_item_block_inner.photo a").text();
        announce = ""; // there are no announces
        date = element.select(".rubric_bytheme_item_block_inner.photo span").text();

        entryNewsList.add(new EntryNews(imgRef, newsRef, title, announce, date));
      }

      return entryNewsList;

    } else if (sectionRef.contains("radio")) {

      entryNewsElements = doc.select(".actual_view_items");
      listItems = entryNewsElements.select(".actual_view_item.clearfix");

      for (Element element : listItems) {
        imgRef = element.select("img").attr("src");
        newsRef = element.select(".actual_view_item_img a").attr("href");
        title = element.select(".actual_view_item_title a").text();
        announce = element.select(".actual_view_item_announce a").text();
        date = ""; // there is no date

        entryNewsList.add(new EntryNews(imgRef, newsRef, title, announce, date));
      }

      return entryNewsList;

    } else if (sectionRef.contains("science")) {

      entryNewsElements = doc.select(".rubric_bytheme_item_block_wrap");
      listItems = entryNewsElements.select(".rubric_bytheme_item_block");

      for (Element element : listItems) {
        imgRef = element.select("img").attr("src");
        newsRef = element.select("a").attr("href");
        title = element.select(".rubric_bytheme_item_block_inner_title").text();
        announce = element.select(".actual_view_item_announce a").text(); // there are no announces
        date = element.select(".rubric_bytheme_item_block_inner.photo span").text();
        entryNewsList.add(new EntryNews(imgRef, newsRef, title, announce, date));
      }

      return entryNewsList;

    } else if (sectionRef.equals("/")) { // main menu

      entryNewsElements = doc.select(".day_news_date.day_news_page");
      listItems = entryNewsElements.select(".day_news_item");
      listItems.addAll(
          entryNewsElements.select(".day_news_items_row .day_news_item.day_news_item_3rd"));

      for (Element element : listItems) {
        imgRef = element.select(" .day_news_item_img img").attr("src");
        newsRef = element.select(" .day_news_item_text .day_news_item_title a").attr("href");
        title = element.select(" .day_news_item_text .day_news_item_title h3").text();
        announce = element.select(" .day_news_item_text .day_news_item_announce a").text();
        date = ""; // there is no date
        entryNewsList.add(new EntryNews(imgRef, newsRef, title, announce, date));
      }

      return entryNewsList;

    } else {

      entryNewsElements = doc.select(".list .list_item");
      listItems = entryNewsElements.select(".list_item_content");

      for (Element element : listItems) {
        imgRef = element.select(".list_item_img img").attr("src");
        newsRef = element.select(".list_item_text .list_item_title a").attr("href");
        title = element.select(".list_item_text .list_item_title a").text();
        announce = element.select(".list_item_text .list_item_announce").text();
        date = element.select(".list_item_text .list_item_date").text();

        entryNewsList.add(new EntryNews(imgRef, newsRef, title, announce, date));
      }

      return entryNewsList;
    }
  }