2

I have a code:

require 'openssl'
require 'open-uri'
require 'rubygems'
require 'nokogiri'
require 'image_downloader'

uri = 'https://aliexpress.com/item/2016-Hot-Sale-Brand-Clothing-Spring-Suit-Blazer-Men-Fashion-Slim-Fit-Masculine-Blazer-Casual-Solid/32759268261.html'
doc = Nokogiri::HTML(open(uri))
strings = doc.text.strip!.split('""') # get massive of quoted links

strings.delete_if { |bite| (bite.include? "alicdn.com/kf/") == false } # delete links that do not include alicdn.com/kf/
strings.map! {|link| URI.extract(URI.encode("#{link}"))} # encoding all links
strings.each_with_index {|f,i| strings[i] = f[0]} #transform a two-dimensional array into one-dimensional

strings.each_with_index do |file, i|
  open(file) { |f|
    File.open("blazer" + "#{i.to_s}" + ".jpg", "wb") do |file| # save image to current directory
      file.puts f.read
    end
  }
end

On Ubuntu it works fine, but on Linux Mint 18.1 Cinnamon it gives an error message:

/usr/lib/ruby/2.3.0/openssl/buffering.rb:322:in `syswrite': Connection reset by peer (Errno::ECONNRESET)

Screenshot:

enter image description here

I googled it, but didn't find normal answers. Can anybode help me?

Gerry
  • 10,337
  • 3
  • 31
  • 40

0 Answers0