Within a Ruby class, I want to parse and fetch the first occurance of an image inside some text that is saved in a database. In particular, I want to collect all src attributes.
Will Nokogiri help me? How can I do it?
Edit1:
I wrote:
// database stuff...
doc = Nokogiri::HTML(my_html)
doc.search('img') do |img_tag|
puts img_tag
end
But I’m not able to collect the image tags.
Edit2:
I found the solution:
doc.search('img').each do |img_tag|
puts img_tag.attributes['src']
end
try this:
See live demo here