Skip to content

Instantly share code, notes, and snippets.

@tonini
Created February 4, 2010 14:24
Show Gist options
  • Save tonini/294667 to your computer and use it in GitHub Desktop.
Save tonini/294667 to your computer and use it in GitHub Desktop.
require 'uri'
require 'open-uri'
require 'nokogiri'
@from = "en"
@to = "de"
@word_to_translate = "accomplish"
@url = "http://www.google.ch/dictionary?source=translation&hl=en&q=##{@word_to_translate}&langpair=#{@from}|#{@to}"
doc = Nokogiri::HTML(open(URI.escape(@url)))
doc.css('li.dct-em span.dct-tt').each do |node|
puts node.text
end
# output:
# schaffen
# vollbringen
# vollenden
# leisten
# durchführen
# erreichen
# durchsetzen
# erzielen
# quantic notation
puts doc.css('div.dct-srch-rslt span.dct-tp').text.split(' ')[0] # [ə’kɒmplɪʃ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment