Last active
December 28, 2015 13:59
-
-
Save amosshapira/7511840 to your computer and use it in GitHub Desktop.
Convert HTML from input files (or standard input, if no file name given) to CSV. Taken from a stackoverflow.com answer I lost since.
This file contains 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
#!/usr/bin/ruby | |
require 'nokogiri' | |
doc = Nokogiri::HTML(ARGF.read) | |
doc.xpath('//table//tr').each do |row| | |
row.xpath('td').each do |cell| | |
print '"', cell.text.gsub("\n", ' ').gsub('"', '\"').gsub(/(\s){2,}/m, '\1'), "\", " | |
end | |
print "\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment