Skip to content

Instantly share code, notes, and snippets.

@caius
Forked from peterc/xkcd_for_ipad.cgi
Created May 21, 2010 07:58
Show Gist options
  • Save caius/408606 to your computer and use it in GitHub Desktop.
Save caius/408606 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
doc = Nokogiri::HTML(open('http://xkcd.com/').read)
image = doc.css("div#contentContainer > div#middleContent > div.bd > div.c > div.s > img")
puts %{Content-type: text/html
<html><head><title>XKCD for iPad</title>
<style type="text/css">BODY { font-family: helvetica; font-size: 16px; text-align: center}
.quip { font-style: italic }</style></head><body>
#{doc.css("h1")}
<p>#{image}</p>
<p class="quip">#{image.attribute("title")}</p>
</body></html>}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment