Equivalent of cURL for Ruby?

前端 未结 12 2644
不知归路
不知归路 2020-11-29 00:33

Is there a cURL library for Ruby?

12条回答
  •  自闭症患者
    2020-11-29 01:18

    Here's a little program I wrote to get some files with.

    base = "http://media.pragprog.com/titles/ruby3/code/samples/tutthreads_"
    
    for i in 1..50
    
      url = "#{ base }#{ i }.rb"
      file = "tutthreads_#{i}.rb"
    
      File.open(file, 'w') do |f|   
        system "curl -o #{f.path} #{url}"
      end
    
    end
    

    I know it could be a little more eloquent but it serves it purpose. Check it out. I just cobbled it together today because I got tired of going to each URL to get the code for the book that was not included in the source download.

提交回复
热议问题