【发布时间】:2018-08-08 19:02:54
【问题描述】:
我试图从这个网站的表格中获得前五名的最高百分比收益并将它们存储到一个数组中。我想打印前 5 名的最高百分比收益。 http://www.wsj.com/mdc/public/page/2_3021-gainnyse-gainer.html
截至目前,我的代码获取所有行和列并将它们打印在输出中。我无法仅获得前 5 个并将它们存储到我的数组中。
请帮忙。
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://www.wsj.com/mdc/public/page/2_3021-gainnyse-gainer.html").get();
Elements rows = doc.select("tr");
for(Element row :rows)
{
Elements columns = row.select("td");
String[][] trtd = new String[columns.size()][];
for (Element column:columns)
{
System.out.println(column.text());
}
System.out.println();
}
}
目前的输出是:
SEARCH
Issue(Roll over for charts and headlines)
Price
Chg
% Chg
Volume
1
PHH (PHH)
$10.71
2.19
25.65
10,865,948
2
Chico's Fas (CHS)
10.03
1.35
15.63
4,514,899
3
Veeva Systems Cl A (VEEV)
70.48
8.41
13.55
3,300,989
4
Tutor Perini (TPC)
24.70
2.85
13.04
1,723,950
5
TriNet Group (TNET)
46.93
5.35
12.87
1,089,758
6
Nelnet Cl A (NNI)
57.60
5.99
11.61
121,379
7
Federal Signal (FSS)
21.35
1.74
8.87
272,982
etc......
【问题讨论】:
-
您是否在每种情况下都按此顺序获取它们?
-
我没有得到与你相同的输出。
标签: java arrays sorting html-table jsoup