require 'cgi/util' htmlfile = 'nisendouka.html' textfile = 'nisendouka.txt' html = File.read(htmlfile) File.open(textfile, 'w') do |f| in_header = true html.each_line do |line| if in_header && /
/ !~ line next else in_header = false end break if /
/ =~ line line.gsub!(/<[^>]+>/, '') esc_line = CGI.unescapeHTML(line) f.write esc_line end end