I'm writing a script using Ruby, Mechanize and Nokogiri to scrape the source attributes from iframe elements on a webpage, and if there's more than one, store them inside an array for later use.
So I have the following code which works, but my question is; Is there a more elegant way of achieving this? Say, something along the lines of iframe.<some_method_like_length>
instead of using the i
counter?
i = 0
doc.search("//span/iframe").each do |iframe|
$ifrmsrc[i] = iframe.attribute("src")
i += 1
end
i = 0
#LATER USE :)
$ifrmsrc.length.times do |g|
puts $ifrmsrc.at(g)
end