Created
January 2, 2011 09:37
-
-
Save tmilewski/762427 to your computer and use it in GitHub Desktop.
Download all Railscasts Episodes
This file contains 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 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
doc = open('http://railscasts.com/') { |f| Hpricot(f) } | |
total_episodes = (doc/'div.number').first.inner_html[1,3].to_i | |
total_pages = (total_episodes / 10).ceil | |
(1..total_pages).each do |i| | |
puts "PAGE #{i} ================================" | |
doc = open("http://railscasts.com/?page=#{i}") { |f| Hpricot(f) } | |
(doc/'div.episode').each do |episode| | |
puts "#{episode.at('div.number').inner_html} - #{episode.at('h2/a').inner_html}" | |
media = episode.at('div.download/a')['href'].scan(/http:\/\/(.*)\/videos(\S*)/)[0] | |
Net::HTTP.start(media[0]) { |http| | |
resp = http.get("/videos/#{media[1]}") | |
open("/Volumes/External\ HD/Tutorials/#{media[1]}", "wb") { |file| | |
file.write(resp.body) | |
} | |
} | |
puts "================================" | |
end | |
end |
railscasts.rb:6:in <main>': undefined method
inner_html' for nil:NilClass (NoMethodError)
this script is showing the above error
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can u plz tell me
how to execute this script & how to download all railscasts videos (free & pro)..?