Last active
April 28, 2016 20:02
-
-
Save beepony/261ae5026bdad1dbf5ebca293802d9db to your computer and use it in GitHub Desktop.
批量 url 下载文件
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
#! /usr/bin/ruby -w | |
# coding:utf-8 | |
require 'net/http' | |
require 'uri' | |
#str = 'http://htmljs.b0.upaiyun.com/uploads/1460943735482-f24c0e5ca2f9d61b48cdd7c215226849.jpg!bac' | |
def downloadurl(str) | |
uri = URI.parse(str) | |
filename = str.split('/')[-1].chomp | |
http_object = Net::HTTP.new(uri.host, uri.port) | |
http_object.use_ssl = true if uri.scheme == 'https' | |
response = Net::HTTP.get_response(uri) | |
f = open(filename, 'wb') | |
f.write(response.body) | |
f.close() | |
filename | |
end | |
file = 'yu2.txt' | |
def get_uri(file) | |
File.open(file,'r') do |f| | |
f.each do |line| | |
downloadurl(line) | |
end | |
end | |
end | |
get_uri(file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment