Created
January 8, 2013 06:29
-
-
Save ssig33/4481723 to your computer and use it in GitHub Desktop.
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 'mechanize' | |
| url = 'http://o.x0.com/m/128' | |
| def save url | |
| id = url.split("/").last | |
| alice = Mechanize.new | |
| page = alice.get(url) | |
| after = page.root.xpath("//a[@rel='next']").first['href'] | |
| title = page.root.xpath("//a[@class='entry-title']").first['title'] | |
| body = page.root.xpath("//*[@id='post-#{id}']/div/div") | |
| open("save/#{id}.txt", 'w'){|f| | |
| f.puts <<EOS | |
| #{title} | |
| #{url} | |
| #{body} | |
| EOS | |
| } | |
| puts "saved #{url}" | |
| after | |
| end | |
| loop{ | |
| url = save url | |
| break unless url != nil and url != '' | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment