【问题标题】:Selecting Display:None With Jsoup选择显示:使用 Jsoup 无
【发布时间】:2013-05-08 18:29:14
【问题描述】:

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

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

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

但这并不适用于所有情况。有时,在样式标签中,有多个属性,例如 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.    


        }

    }

应该采取什么方法来完成这项工作?

【问题讨论】:

    标签: java jsoup


    【解决方案1】:

    您可以为您的选择器尝试valContaining 构造,如下所示:

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

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

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

    【讨论】:

    • 似乎正则表达式是一种选择。
    猜你喜欢
    • 2013-11-25
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-03
    相关资源
    最近更新 更多