私は、グローバル通貨ペアに関する履歴データを収集する必要がある小さなプロジェクトを開始しました。この質問Extract Data out of table with JSoupからの答えに続いて、私は以下のコードを貼り付けました。JSoup - テーブルデータの抽出エラー
しかし、 'data' Elements配列のサイズは7ですが、私はIndexOutOfBoundException
を受け取りますか?
私は頭を一時間ほど掻き回してきました。誰かが間違っている箇所を指摘できるかどうか分かりました。
メインクラス
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import org.jsoup.*;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class MainClass {
public static void main(String[] args) throws IOException{
Document doc = Jsoup.connect("http://www.myfxbook.com/forex-market/currencies/GBPUSD-historical-data").get();
Element table = doc.getElementById("symbolMarket");
List<Entry> entries = new ArrayList<Entry>();
for(Element row : table.select("tr")){
int index = 0;
Entry tableEntry = new Entry();
Elements data = row.select("td");
tableEntry.setDate(data.get(index++).text());
tableEntry.setOpen(data.get(index++).text());
tableEntry.setHigh(data.get(index++).text());
tableEntry.setLow(data.get(index++).text());
tableEntry.setClose(data.get(index++).text());
tableEntry.setChangePips(data.get(index++).text());
tableEntry.setChangePercent(data.get(index++).text());
entries.add(tableEntry);
}
}
}
エントリークラス
public class Entry {
private String date;
private String open;
private String high;
private String low;
private String close;
private String changePips;
private String changePercent;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getOpen() {
return open;
}
public void setOpen(String open) {
this.open = open;
}
public String getHigh() {
return high;
}
public void setHigh(String high) {
this.high = high;
}
public String getLow() {
return low;
}
public void setLow(String low) {
this.low = low;
}
public String getClose() {
return close;
}
public void setClose(String close) {
this.close = close;
}
public String getChangePips() {
return changePips;
}
public void setChangePips(String changePips) {
this.changePips = changePips;
}
public String getChangePercent() {
return changePercent;
}
public void setChangePercent(String changePercent) {
this.changePercent = changePercent;
}
}