Want more features on Pastebin? Sign Up, it's FREE!
Guest

App

By: a guest on Oct 7th, 2012  |  syntax: None  |  size: 1.83 KB  |  views: 96  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.infobip.jsouptest;
  2.  
  3. import java.io.IOException;
  4. import java.util.*;
  5. import java.util.concurrent.*;
  6. import java.util.logging.Level;
  7. import java.util.logging.Logger;
  8. import org.jsoup.Jsoup;
  9. import org.jsoup.nodes.Document;
  10. import org.jsoup.nodes.Element;
  11. import org.jsoup.select.Elements;
  12.  
  13. /**
  14.  * Hello world!
  15.  *
  16.  */
  17. public class App
  18. {
  19.  
  20.    
  21.     public static void main( String[] args ) throws IOException
  22.     {
  23.        
  24.         ExecutorService executorService = Executors.newFixedThreadPool(5);
  25.         List<Future<Document>> handles = new ArrayList<Future<Document>>();
  26.         List<Callable<Document>> requests = new ArrayList<Callable<Document>>();
  27.        
  28.         Document d = Jsoup.connect("http://www.betexplorer.com/results/").timeout(0).get();
  29.         Elements elements = d.select("a");        
  30.         Iterator<Element> it = elements.iterator();
  31.         Element e;        
  32.         while(it.hasNext()) {
  33.             e = it.next();
  34.             //System.out.println(e.attr("href"));            
  35.             if (e.attr("href").startsWith("/soccer")) {
  36.                 requests.add(new Request("http://www.betexplorer.com"+e.attr("href")));
  37.             }
  38.         }        
  39.        
  40.         System.out.println("soccer requests size : "+requests.size());
  41.         System.out.println(Arrays.deepToString(requests.toArray()));
  42.        
  43.        
  44.        
  45.         for (Callable<Document> request : requests) {
  46.             handles.add(executorService.submit(request));
  47.         }
  48.        
  49.        
  50.         for (Future<Document> h : handles) {
  51.             try {
  52.                 d = h.get();
  53.                 System.out.println(d.title());
  54.             }
  55.             catch (Exception ex) {
  56.                 ex.printStackTrace();
  57.             }
  58.         }
  59.        
  60.         executorService.shutdownNow();
  61.     }
  62. }
clone this paste RAW Paste Data