Created
August 22, 2021 00:36
-
-
Save seki/53859ad1a07d5cce239fec5485e43b4c to your computer and use it in GitHub Desktop.
fetch DICOM DE
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
require 'nokogiri' | |
require 'open-uri' | |
fname = ARGV.shift | |
if fname | |
html = File.read(fname) | |
else | |
url = "http://dicom.nema.org/medical/dicom/current/output/chtml/part06/chapter_6.html" | |
html = URI.open(url).read | |
File.write("/tmp/chapter6.html", html) | |
end | |
tree = Nokogiri::HTML(html) | |
tbody = tree.at_css("#table_6-1 ~ div > table > tbody") | |
table6_1 = tbody.css('tr').map do |tr| | |
ary = tr.css('td').map {|x| x.text.strip} | |
ary[0] = ary[0].scan(/\((....),(....)\)/).flatten.join | |
ary[2] = ary[2].split("\u200b").join | |
ary[0,5] | |
end | |
pp table6_1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment