【问题标题】:Retrieve iframe tag having width and height '0' using nokogiri in ruby 1.9.2在 ruby​​ 1.9.2 中使用 nokogiri 检索具有宽度和高度“0”的 iframe 标签
【发布时间】:2012-03-19 07:14:39
【问题描述】:

我想从html 代码中检索iframe 标记,其宽度和高度值为0(零) 在Ruby 1.9.2中使用nokogiri gem

【问题讨论】:

    标签: ruby ruby-on-rails-3.1 nokogiri ruby-1.9.2


    【解决方案1】:

    单个 xpath 语句就可以解决问题:

    doc.xpath('//iframe[@width="0" and @height="0"]')
    

    这假定所有内容都存在于检索到的 HTML 中。如果 iframewidthheight 仅在 javascript 执行后出现在 DOM 中,这将不起作用。

    【讨论】:

      【解决方案2】:

      阅读 nokogiri 文档就足够了,但是:假设您的 html 文档存储在 raw_document 中,您可以使用 doc = Nokogiri::HTML(raw_document)。然后您可以使用doc.css('iframe') 获取所有 iframe 标记的列表,并对其进行迭代以仅选择您想要的标记。 doc.css('iframe[width=0], iframe[height=0]') 之类的东西可能会直接这样做,但我不能保证。

      【讨论】:

        猜你喜欢
        • 2018-01-29
        • 2020-08-16
        • 2014-01-24
        • 2011-12-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多