Advertisement
vitalijzad

Estrazioni numeri lotto

Nov 29th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1.  
  2.         Map<String, List<Integer>> numeriEstratti = new HashMap<String, List<Integer>>();
  3.  
  4.         // NB: controllate di importare le classi giuste
  5.         Document doc = Jsoup.connect("http://www.estrazionedellotto.it/").timeout(0).get();
  6.         //.userAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22")
  7.         //.timeout(30000).get();
  8.  
  9.         //System.out.println("doc"+doc);
  10.  
  11.         // prendo la tabella
  12.         // (con .first() ottengo il primo elemento, in questo caso l'unico )
  13.         Elements elements = doc.getElementsByAttributeValueContaining("class", "nomeRuota estratto");
  14.  
  15.         for(Element element : elements){
  16.             Element parent = element.parent();
  17.             String chiave = element.text();
  18.             List<Integer> numeri = new ArrayList<Integer>();
  19.             for(Element e : parent.children()){
  20.                 System.out.println(e.text());
  21.                 if(e.text().length() > 0) {
  22.                     try {
  23.                         Integer numero = Integer.parseInt(e.text());
  24.                         numeri.add(numero);
  25.                     }catch (NumberFormatException nfe){
  26.                         // TODO
  27.                     }
  28.                 }
  29.             }
  30.             numeriEstratti.put(chiave, numeri);
  31.         }
  32.  
  33.         System.out.println(numeriEstratti);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement