Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

require 'open-uri'; (1..34).to_a.each{|x| open('http://www.dspguide.com/CH'+x.to_s+'.PDF'){|u| File.open("CH#{x}.PDF","w"){|f|f.puts u.readlines}}}


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').read)}


Ah, 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.


This 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'){|u| File.open("CH#{x}.PDF","wb"){|f|f.puts u.readlines}}}




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: