Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
Add Comment
Please, Sign In to add comment