• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.jsoup.examples;
2 
3 import org.jsoup.Jsoup;
4 import org.jsoup.nodes.Document;
5 import org.jsoup.nodes.Element;
6 import org.jsoup.select.Elements;
7 
8 import java.io.IOException;
9 
10 /**
11  * A simple example, used on the jsoup website.
12  */
13 public class Wikipedia {
main(String[] args)14     public static void main(String[] args) throws IOException {
15         Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
16         log(doc.title());
17 
18         Elements newsHeadlines = doc.select("#mp-itn b a");
19         for (Element headline : newsHeadlines) {
20             log("%s\n\t%s", headline.attr("title"), headline.absUrl("href"));
21         }
22     }
23 
log(String msg, String... vals)24     private static void log(String msg, String... vals) {
25         System.out.println(String.format(msg, vals));
26     }
27 }
28