8 ms·
Thanks nickb. If you are on a windows machine you need to use "wb" instead of "w" for this to work. Here is a version that works on windows: require 'open-uri'
by luccastera 19y ago
Thanks nickb. If you are on a windows machine you need to use "wb" instead of "w" for this to work. Here is a version that works on windows:
require 'open-uri';(1..34).to_a.each{|x| open("CH#{x}.PDF", "wb").write(open('http://www.dspguide.com/CH1.PDF' http://www.dspguide.com/CH1.PDF').read)}
- nickb 19y agoAh, good to know! Thanks! PS: Those who are wondering wtf this is all about, save it as book.rb and run 'ruby book.rb' and it will grab all the PDFs of that book for you.
- pchristensen 18y agoThis didn't work for me. I just changed "w" to "wb" on XP and nickb's original worked fine: require 'open-uri'; (1..34).to_a.each{|x| open('http://www.dspguide.com/CH'+x.to_s+'.PDF' http://www.dspguide.com/CH'+x.to_s+'.PDF'){|u| File.open("CH#{x}.PDF","wb"){|f|f.puts u.readlines}}}