rubyruby-on-rails-3.1nokogiriruby-1.9.2

Retrieve iframe tag having width and height '0' using nokogiri in ruby 1.9.2


I want to retrieve the iframe tags from html code, whose width and height values are 0(zero) using nokogiri gem in Ruby 1.9.2


Solution

  • A single xpath statement will do the trick:

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

    This assumes that everything is present in the retrieved HTML. If the iframe, width, or height are only present in the DOM after javascript execution, this will not work.