Skip to content

Instantly share code, notes, and snippets.

@worker8
Created August 21, 2018 05:46
Show Gist options
  • Select an option

  • Save worker8/a17535193136cf8f6f28f3cf0a04b906 to your computer and use it in GitHub Desktop.

Select an option

Save worker8/a17535193136cf8f6f28f3cf0a04b906 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'pry'
require 'open-uri'
class Parse
def loadFile
puts "start.."
file = File.read("raw_html5")
result = Nokogiri::XML(file)
rootNode = result.children
image_elements = []
rootNode.children.each do |x|
if x.is_a?(Nokogiri::XML::Element)
image_elements.push x
end
end
image_elements.shift
final_elements = []
image_elements.each {|x|
begin
if x.children.first(2).last.attributes.first.last.value == "custom_emoji_image"
final_elements.push x.children.first(2).last
end
rescue
end
}
yay_array = final_elements.collect {|x| x.children.first.attributes["data-original"].value}
yay_array1 = []
yay_array.each {|x|
extension = x.split("/").last.split(".").last
only_filename = x.split("/").last(2).first
yay_array1.push({:filename => "#{only_filename}.#{extension}", :url => x})
}
yay_array1
end
end
array = Parse.new.loadFile
array.each {|x|
begin
File.open("emojis/#{x[:filename]}", 'w') {|file|
file.write(open(x[:url]).read)
}
rescue
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment