简体   繁体   English

JSoup,删除元素

[英]JSoup, remove Elements

Basically what I want to achieve is to remove the elements that have a colspan=2 and only leave the other Elements. 基本上,我要实现的是删除具有colspan=2的元素,而仅保留其他元素。 I am actually trying it with this code but it's not working, any Ideas ? 我实际上正在使用此代码进行尝试,但是没有任何效果吗? :) :)

So this is my Code: 这是我的代码:

try {
      docSpielTagSpiele = Jsoup.connect(url).get();
} catch (IOException ex) {
      Logger.getLogger(FullFrame.class.getName()).log(Level.SEVERE, null, ex);
}

Elements spieltagElements = docSpielTagSpiele.select("div#Content > div.rahmen > div.rahmenbody > table.Spiele > tbody > tr > td.Heim");
System.out.println(spieltagElements);
System.out.println("SIZE: " + spieltagElements.size());

System.out.println("------------------------------------------------------------------------");

Elements el = spieltagElements.select("td.Heim[colspan=2]").remove();

System.out.println(el);
System.out.println("SIZE: " + el.size());

System.out.println("------------------------------------------------------------------------");

System.out.println("ELEMENTS THAT NEED TO BE REMOVED");
Elements remove = spieltagElements.select("td.Heim[colspan=2]");
System.out.println(remove);
System.out.println("SIZE: " + remove.size());

and this is my output: 这是我的输出:

http://pastebin.com/ajY88FGn (can't show it directly, though the editor is parsing it directly...) http://pastebin.com/ajY88FGn (虽然编辑器直接对其进行解析,但无法直接显示它...)

Thanks already :) 已经谢谢你了:)

Your method works as it should. 您的方法可以正常工作。 The elements are removed from the DOM, as explained in the documentation . 文档所述,将元素从DOM中删除。 The remove method does not empty the collection of elements that you prepared before. remove方法不会清空您之前准备的元素的集合。 So spieltagElements will remain as it was. 因此spieltagElements将保持原样。 The document docSpielTagSpiele however does not contain the removed elements any more. 但是,文档docSpielTagSpiele不再包含已删除的元素。 To see that, you need to query the original docSpielTagSpiele again. 为此,您需要再次查询原始docSpielTagSpiele

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM