0

Выводит правильно, но выдаёт ошибку

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at Main.main(Main.java:26)

вот код

public static void main(String[] args) throws IOException{

    ArrayList<Integer> list = new ArrayList<Integer>();


    Document doc = Jsoup.connect("https://free-proxy-list.net/").get();


    Element table = doc.select("table").first();


    Elements rows = table.select("tr");

    for (int i = 1; i < rows.size(); i++){
        Element row = rows.get(i); 
        Elements cols = row.select("td"); 
        System.out.println(cols.get(0).text()); 
        System.out.println(cols.get(1).text()); 
        System.out.println();
    }
}

1 ответ 1

1

Выбираете все tr из table, а там в tfoot есть такая, в которой нет ни одного td.

Лучше всего добавить проверку на кол-во td, чтобы их было 2, прежде, чем обращаться к 0 и 1.

1
  • большое спасибо
    – user235073
    3 апр 2018 в 12:06

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.