daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. *   Простой парсер для обучения. библиотека jsoup.
  3. *
  4. *
  5. *
  6.  */
  7. import org.jsoup.Jsoup;
  8. import org.jsoup.nodes.Document;
  9. import org.jsoup.select.Elements;
  10.  
  11. import java.io.IOException;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14.  
  15. public class Parser {
  16.     public static void main(String[] args) throws IOException {
  17.  
  18.         List<Article> articleList = new ArrayList<>();
  19.  
  20.         Document doc = Jsoup.connect("http://www.ksrf.ru/ru/Pages/default.aspx").get();
  21.  
  22.         Elements tdElements = doc.getElementsByAttributeValue("style", "font-family:Arial;font-size:larger");
  23.  
  24.         tdElements.forEach(tdElement -> {
  25.             String title = tdElement.ownText();
  26.  
  27.             articleList.add(new Article(title));
  28.                 });
  29.  
  30.         articleList.forEach(System.out::println);
  31.  
  32.         System.out.println();
  33.     }
  34. }
  35.  
  36. class Article {
  37.     private String text;
  38.  
  39.     public Article (String text){
  40.         this.text = text;
  41.     }
  42.  
  43.  
  44.     public String getText() {
  45.         return text;
  46.     }
  47.  
  48.     public void setText(String text) {
  49.         this.text = text;
  50.     }
  51.  
  52.     @Override
  53.     public String toString() {
  54.         return "Article{" +
  55.                 "text='" + text + '\'' +
  56.                 '}';
  57.     }
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top