Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Last active December 23, 2015 00:29
Show Gist options
  • Select an option

  • Save ryanfb/6553866 to your computer and use it in GitHub Desktop.

Select an option

Save ryanfb/6553866 to your computer and use it in GitHub Desktop.
e-codices downloader - http://www.e-codices.unifr.ch/
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
def download_pages(uri, id)
doc = Nokogiri::HTML(open(uri))
doc.xpath('//select[@id = "page_select"]/option/@value').each do |value|
page = value.to_s.split('/').last
page_uri = "#{uri}/#{page}/x-large"
page_doc = Nokogiri::HTML(open(page_uri))
page_doc.xpath('//img[@id = "msImage"]/@src').each do |image|
`wget "#{image.to_s}"`
end
end
end
# e.g. 10.5076/e-codices-kba-Ms-FZ-0018
doi = ARGV[0]
# kba-Ms-FZ-0018
id = doi[/e-codices-(.*)/,1]
# kba
collection = id.split('-').first
# Ms-FZ-0018
document = id[/#{collection}-(.*)/,1]
prefix = "http://www.e-codices.unifr.ch/en/"
pages_uri = prefix + "#{collection}/#{document}"
binding_uri = prefix + "binding/#{collection}/#{document}"
`wget "http://www.e-codices.unifr.ch/xml_descriptions/#{id}.xml"`
[binding_uri, pages_uri].each {|uri| download_pages(uri, id)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment