Guest User

Untitled

a guest
Aug 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. require 'nokogiri'
  2. require 'pry'
  3. require 'open-uri'
  4.  
  5. class Parse
  6. def loadFile
  7. puts "start.."
  8. file = File.read("raw_html5")
  9. result = Nokogiri::XML(file)
  10. rootNode = result.children
  11. image_elements = []
  12. rootNode.children.each do |x|
  13. if x.is_a?(Nokogiri::XML::Element)
  14. image_elements.push x
  15. end
  16. end
  17. image_elements.shift
  18. final_elements = []
  19.  
  20. image_elements.each {|x|
  21. begin
  22. if x.children.first(2).last.attributes.first.last.value == "custom_emoji_image"
  23. final_elements.push x.children.first(2).last
  24. end
  25. rescue
  26. end
  27. }
  28.  
  29. yay_array = final_elements.collect {|x| x.children.first.attributes["data-original"].value}
  30.  
  31. yay_array1 = []
  32. yay_array.each {|x|
  33. extension = x.split("/").last.split(".").last
  34. only_filename = x.split("/").last(2).first
  35. yay_array1.push({:filename => "#{only_filename}.#{extension}", :url => x})
  36. }
  37. yay_array1
  38. end
  39. end
  40.  
  41. array = Parse.new.loadFile
  42.  
  43. array.each {|x|
  44. begin
  45. File.open("emojis/#{x[:filename]}", 'w') {|file|
  46. file.write(open(x[:url]).read)
  47. }
  48. rescue
  49. end
  50. }
Add Comment
Please, Sign In to add comment