전 세계 통화 쌍에 대한 과거 데이터를 수집해야하는 소규모 프로젝트를 시작했습니다. 이 질문에 대한 답변을 Extract Data out of table with JSoup 다음에 붙여 넣습니다.JSoup - 테이블 데이터 추출 오류
그러나 '데이터'요소 배열의 크기가 7이지만 IndexOutOfBoundException
을 계속 수신합니까?
저는 거의 한시간 내 머리를 긁적 거리며 누군가가 내가 잘못한 곳을 지적 할 수 있으면 감사 할 것입니다! '데이터'요소 배열의 사이즈 (7) 비록
메인 클래스
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;
}
}