Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/http'
- require 'open-uri'
- require 'fastimage'
- require 'json'
- downloaded_urls = []
- while(true)
- uri = URI('http://radikal.ru/Img/GetGalleryPage')
- params = { AnchorId: "", PageSize: 40 }
- uri.query = URI.encode_www_form(params)
- begin
- page = Net::HTTP.get(uri)
- rescue Exception => e
- next
- end
- JSON.parse(page)["Imgs"].map { |e| e["Url"] }.each do |url|
- next if downloaded_urls.include?(url)
- image_path = "images/#{Time.now.to_i}_#{File.basename(url)}"
- size = FastImage.size(url)
- next if size.nil? || (size.first < 350 && size.last < 350)
- File.open(image_path, 'wb') do |output|
- puts "Загружаю #{url}..."
- begin
- output.write(open(url, "rb").read)
- downloaded_urls << url
- rescue Exception => e
- puts "[!] Не удалось загрузить #{url}"
- end
- end
- end
- sleep(10.0)
- end
Advertisement
Add Comment
Please, Sign In to add comment