Created
February 25, 2013 04:16
-
-
Save djburdick/5027714 to your computer and use it in GitHub Desktop.
move posterous code posts to gists. #ruby
This file contains hidden or 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 '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