Skip to content

Instantly share code, notes, and snippets.

@codealchemy
Created August 29, 2015 19:02
Show Gist options
  • Select an option

  • Save codealchemy/5a47671095b39beeba89 to your computer and use it in GitHub Desktop.

Select an option

Save codealchemy/5a47671095b39beeba89 to your computer and use it in GitHub Desktop.
Pulls each image from html content to clean urls to match to uploaded page attachments in NationBuilder
require 'csv'
require 'nokogiri'
CSV.open('slug_with_image.csv', 'w') do |csv|
CSV.foreach('blog_file.csv', headers: true) do |row|
content_html = Nokogiri::HTML(row['content'])
content_html.css('img').each do |img|
csv << [img['src'], row['slug']]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment