gpt4 book ai didi

java - 选择显示 :None With Jsoup

转载 作者:行者123 更新时间:2023-12-01 14:19:22 25 4
gpt4 key购买 nike

我正在使用 JSoup 进行练习,以了解这个惊人的解析器的可能性。有一件事我无法解决:

我需要删除带有 display none 属性的标签。一种明显的方法是使用 select :

doc.select("*[style=display:none]").remove();

但这并不适用于所有情况。有时,在 style 标签中,有多个属性,如 style="display:none,width...."有时,还有空格、冒号等,如 style="display: none;"。

我试图通过应用来解决这个问题:

if(!doc.getElementsByAttributeValueContaining("style", "display").isEmpty()){
if(!doc.getElementsByAttributeValueContaining("style", "none").isEmpty()){

// Not sure what to remove here.


}

}

完成这项工作的方法应该是什么?

最佳答案

您可以像这样为您的选择器尝试 valContaining 结构:

doc.select("*[style*=display:none]").remove();

如果这与您想要的不匹配,请尝试查看此处的文档以获取更多选项:

http://jsoup.org/apidocs/org/jsoup/select/Selector.html

关于java - 选择显示 :None With Jsoup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16447705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com