Skip to content

Instantly share code, notes, and snippets.

@ichoake
Forked from michaelficarra/etsy-scrape.rb
Created December 31, 2022 01:47
Show Gist options
  • Save ichoake/5719c85574cb240122c609f038000f93 to your computer and use it in GitHub Desktop.
Save ichoake/5719c85574cb240122c609f038000f93 to your computer and use it in GitHub Desktop.
download all the listing images from a given etsy shop
require 'etsy'
Etsy.api_key = '<api-key>'
shop = Etsy::Shop.find '<shop-name>'
out_dir = '<output-directory>'
Etsy.environment = :production
Dir.mkdir out_dir unless File.exists? out_dir
listings = []
offset = 0
begin
nListings = listings.length
listings.concat Etsy::Listing.find_all_by_shop_id(shop.id, :limit => 100, :offset => offset)
offset += 100
end while listings.length > nListings
images = listings.map {|l| l.images.map {|i| i.full } }
images.flatten!
images.map do |image_url|
uri = URI.parse image_url
out_file = File.join out_dir, File.basename(uri.path)
unless File.exists? out_file
response = Net::HTTP.get_response uri
File.open(out_file, "w"){|f| f.write response.body }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment