Created
August 21, 2018 05:46
-
-
Save worker8/a17535193136cf8f6f28f3cf0a04b906 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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