Skip to content

Instantly share code, notes, and snippets.

@jphenow
Created January 26, 2017 22:28
Show Gist options
  • Save jphenow/2a9c4f13238edc60352082c995292c71 to your computer and use it in GitHub Desktop.
Save jphenow/2a9c4f13238edc60352082c995292c71 to your computer and use it in GitHub Desktop.
Scrape Slack html for a team's emojis, download them and rename them so you can use elsewhere
#!/usr/bin/env ruby
# Go to emoji customization page on your Slack org
# download the html for that page
# Also need "nokogiri" installed
#
# Usage: scrape <htmlfile>
require 'nokogiri'
require 'open-uri'
file = ARGV[0]
doc = Nokogiri::XML(File.open(file))
`mkdir -p download`
doc.xpath("//tr[contains(@class, 'emoji_row')]").each do |tr|
emoji_span = tr.xpath(".//span[contains(@class, 'emoji-wrapper')]").first
name = tr.xpath(".//td[contains(@headers, 'custom_emoji_name')]").first.content.strip.gsub(":", "")
if emoji_span && name
url = emoji_span["data-original"]
ext = url.split(".").last
puts "Downloading: #{name} from #{url}"
open("download/#{name}.#{ext}", 'wb') do |f|
f << open(url).read
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment