binarapps / feedjira-with-rails

MIT License
6 stars 4 forks source link

Extract images from content #2

Open Pantic14 opened 9 years ago

Pantic14 commented 9 years ago

Hi, How do extract the images that exist within the tag content? I need to extract images by one side and text on the other. Thanks.

CucumisSativus commented 9 years ago

I would say the best way to do this is to use nokogiri, which is already used for feedjira so no need to include another gem. To obtain images sources please try this code

doc = Nokogiri::HTML(entry.content)
doc.xpath('//img').each do |link|
  puts link.attributes['src']
end

You can of course put images sources to an array or something instead of printing. Good luck with this!