thieumao

Jsoup demo lấy kêt quả xổ số

Nov 22nd, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package com.mkyong;
  2.  
  3. import java.io.IOException;
  4. import org.jsoup.Jsoup;
  5. import org.jsoup.nodes.Document;
  6. import org.jsoup.nodes.Element;
  7. import org.jsoup.select.Elements;
  8.  
  9. public class testXoSo {
  10.  
  11.     public static void main(String[] args) {
  12.  
  13.         Document doc;
  14.         try {
  15.  
  16.             // need http protocol
  17.             doc = Jsoup.connect("http://ketquaxoso.24h.com.vn/").get();
  18.  
  19.             // get page title
  20.             String title = doc.title();
  21.             System.out.println("title : " + title);
  22.  
  23.             // get all links
  24.             Elements links = doc.select("td[class]");
  25.             for (Element link : links) {
  26.  
  27.                 // get the value from href attribute
  28.                 if (link.attr("class").equals("number_kq")) {
  29. //                    System.out.println("\nlink : " + link.attr("class"));
  30.                     System.out.println("text : " + link.text());
  31.                 }
  32.  
  33.             }
  34.  
  35.         } catch (IOException e) {
  36.             e.printStackTrace();
  37.         }
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment