Skip to content

Instantly share code, notes, and snippets.

@rclavel
Created July 18, 2016 15:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rclavel/609e8321502015cabea28de840191ab1 to your computer and use it in GitHub Desktop.
Save rclavel/609e8321502015cabea28de840191ab1 to your computer and use it in GitHub Desktop.
require 'json'
require 'nokogiri'
require 'mechanize'
puts 'Get source'
agent = Mechanize.new
html = agent.get 'http://bulbapedia.bulbagarden.net/wiki/List_of_French_Pok%C3%A9mon_names'
nodes = Nokogiri::HTML.parse html.body
puts 'Parse html'
translations = {fr: {}, en: {}}
nodes.css('#mw-content-text > table > tr')
.select do |x|
x.children.count{|y| y.name == 'td'} == 4
end.each do |x|
c = x.children.select{|x| x.name == 'td'}
code = c[0].text.strip
if code[/[0-9]/]
translations[:en][code.to_i] = c[2].text.strip
translations[:fr][code.to_i] = c[3].text.strip
end
end
puts 'Write pokemon.fr.json'
File.write 'pokemon.fr.json', translations[:fr].to_json
puts 'Write pokemon.en.json'
File.write 'pokemon.en.json', translations[:en].to_json
puts 'Done!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment