Skip to content

Instantly share code, notes, and snippets.

@djburdick
Created February 25, 2013 04:16
Show Gist options
  • Select an option

  • Save djburdick/5027714 to your computer and use it in GitHub Desktop.

Select an option

Save djburdick/5027714 to your computer and use it in GitHub Desktop.
move posterous code posts to gists. #ruby
require 'open-uri'
require 'nokogiri'
def scrape
29.times do |i|
page = i + 1
url = "http://djcode.posterous.com/?page=#{page}"
doc = Nokogiri::HTML(open(url))
doc.css('div.postunit').each do |c|
code_out = ""
code = c.css('pre').each_with_index {|d,i| code_out += "#{d.text}\n" }
title = c.at_css('h2').text
text = c.at_css('p').text
is_text = text.gsub(/\W/,'')
tag = c.css('div.infobar').at_css('a').text
title_out = "#{title}. ##{tag}"
text_out = "#" + text + "\n" if is_text != ""
`echo "#{code_out}#{text_out}" | gist -d "#{title_out}"`
puts "=========="
end
end
end
scrape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment