How to remove an element from a group of elements?

前端 未结 2 1315
别那么骄傲
别那么骄傲 2021-01-19 06:56

Given the code below:

HTML:

a
b
c&
2条回答
  •  耶瑟儿~
    2021-01-19 07:20

    This should help you:

    public class TestJsoup {
    
        public static void main(String[] args) {
            try {
                Document doc = Jsoup.connect("http://www.google.ro").get();
                Elements select = doc.select("div");
                System.out.println(select.size());
                select.remove(1);
                System.out.println(select.size());
            } catch (IOException ex) {
                Logger.getLogger(TestJsoup.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    

提交回复
热议问题