Skip to content

Instantly share code, notes, and snippets.

@murparreira
Created April 12, 2019 13:57
Show Gist options
  • Save murparreira/7e83341809e2e3833042c6382a9cd148 to your computer and use it in GitHub Desktop.
Save murparreira/7e83341809e2e3833042c6382a9cd148 to your computer and use it in GitHub Desktop.
Script that downloads all Smash Bros Ultimate Spirits images and descriptions
require 'rubygems'
require 'mechanize'
range = (795..1303)
FOLDER_PATH = "/path/to/your/running/script/"
range.each do |number|
array = []
agent = Mechanize.new
puts "Visiting #{number} page!"
number_page = agent.get("https://smashultimatespirits.com/details.php?id=#{number}")
noko = Nokogiri::HTML(number_page.body)
image_tag = noko.at_css('.dImg img').attr('src')
image_alt = noko.at_css('.dImg img').attr('alt')
puts "Found image source!"
agent.get(image_tag).save FOLDER_PATH+image_alt.downcase.split.join('_')+".png"
puts "Saving #{image_alt} image!"
puts "Found image description!"
description = noko.at_css('.dDesc').text
file = File.open("#{image_alt}.txt", "w")
file.puts description
file.close
puts "Description saved to file #{image_alt}.txt"
end
puts "Removing extra images!"
Dir.foreach(FOLDER_PATH) do |img|
File.delete(FOLDER_PATH+img) unless img.match(/\.\d+/).nil?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment