-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathWikipedia.java
More file actions
30 lines (25 loc) · 963 Bytes
/
Copy pathWikipedia.java
File metadata and controls
30 lines (25 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package org.jsoup.examples;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
/**
* A simple example, used on the jsoup website.
<p>To invoke from the command line, assuming you've downloaded the jsoup-examples
jar to your current directory:</p>
<p><code>java -cp jsoup-examples.jar org.jsoup.examples.Wikipedia url</code></p>
*/
public class Wikipedia {
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("https://en.wikipedia.org/").get();
log(doc.title());
Elements newsHeadlines = doc.select("#mp-itn b a");
for (Element headline : newsHeadlines) {
log("%s\n\t%s", headline.attr("title"), headline.absUrl("href"));
}
}
private static void log(String msg, String... vals) {
System.out.println(String.format(msg, (Object[]) vals));
}
}