문제

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

도움이 되었습니까?

해결책

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.

다른 팁

Reading the nokogiri doc should be enough, but : assuming your html doc is stored in raw_document, you can do doc = Nokogiri::HTML(raw_document). Then you can use doc.css('iframe') to get the list of all iframe tags, and iterate over it to select only the ones you want. Something like doc.css('iframe[width=0], iframe[height=0]') might do it directly, but I can't assure it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top