【问题标题】:Using jsoup is there a way to get anchor tags that are within div tags with class attribute that have display none style in the css class..?使用 jsoup 有没有办法获取 div 标签内的锚标签,其 class 属性在 css 类中没有显示样式..?
【发布时间】:2013-09-04 07:15:40
【问题描述】:

我有一个文档,我试图从中提取 a 标签。其中一些位于具有 class 属性的 div 标记中,并且该类具有 display:none 属性集。它们不会直接使用 div 标签中的 style 属性隐藏。我想消除那些。使用链接标签将 css 包含在页面中。

【问题讨论】:

    标签: css class styles jsoup extract


    【解决方案1】:

    选择所有<a>-tags 并搜索是否有一个父母是带有隐藏类的<div>

    for (Element a : doc.getElementsByTag("a")) {
        for (Element parent : a.parents()) {
            if (parent.tagName().equals("div") && parent.hasClass("hidden")) {
                a.remove();
            }
        }
    }
    

    或者更简单 - 只需使用隐藏类删除 <div> 中的所有锚点:

    doc.select("div.hidden a").remove();
    

    【讨论】:

      猜你喜欢
      • 2015-11-07
      • 2021-05-17
      • 1970-01-01
      • 2020-08-11
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      • 2020-11-01
      相关资源
      最近更新 更多