回答編集履歴
1
コードを実行できるものに変更
test
CHANGED
@@ -1,6 +1,28 @@
|
|
1
1
|
html をテキストエディタででも読めば、ランキングデータの(欲しい情報が入っている) a タグには特定の属性があることが分かります。
|
2
2
|
後は jsoup の API をどう使用するかですから、見るべきは API のドキュメントで、開発者ツールとかデバッガとかは必要無いでしょう。
|
3
3
|
```java
|
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 Ranking {
|
10
|
+
public static void main(String[] args) throws Exception {
|
11
|
+
Document doc = Jsoup.parse(
|
12
|
+
"<a href='https://example.com/00100' data-i3ref='list' data-listorder='1' onmousedown=\"\">\n"
|
13
|
+
+ "<span class=\"img\">\n"
|
14
|
+
+ "<img src=\"https://example.com/image00100.jpg\" alt=\"title 00100\">\n"
|
15
|
+
+ "</span>\n"
|
16
|
+
+ "<span class=\"txt\">title 00100</span>\n"
|
17
|
+
+ "</a>"
|
18
|
+
+ "<a href='https://example.com/00120' data-i3ref='list' data-listorder='2' onmousedown=\"\">\n"
|
19
|
+
+ "<span class=\"img\">\n"
|
20
|
+
+ "<img src=\"https://example.com/image00120.jpg\" alt=\"title 00120\">\n"
|
21
|
+
+ "</span>\n"
|
22
|
+
+ "<span class=\"txt\">title 00120</span>\n"
|
23
|
+
+ "</a>"
|
24
|
+
);
|
25
|
+
|
4
26
|
Elements elements = doc.select("a[data-listorder]");
|
5
27
|
for(int i=0; i<Math.min(10, elements.size()); i++) {
|
6
28
|
Element element = elements.get(i);
|
@@ -8,4 +30,14 @@
|
|
8
30
|
System.out.println("href=" + element.attr("href"));
|
9
31
|
System.out.println("title=" + element.text());
|
10
32
|
}
|
33
|
+
}
|
34
|
+
}
|
11
35
|
```
|
36
|
+
```
|
37
|
+
order=1
|
38
|
+
href=https://example.com/00100
|
39
|
+
title=title 00100
|
40
|
+
order=2
|
41
|
+
href=https://example.com/00120
|
42
|
+
title=title 00120
|
43
|
+
```
|