Ruby脚本。通过对等方重置连接(Errno :: ECONNRESET)

时间:2017-06-17 13:28:17

标签: ruby

我有一个代码:

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

在Ubuntu上它工作正常,但在Linux Mint 18.1 Cinnamon上它会显示错误信息:

  

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

截图:

enter image description here

我用谷歌搜索了,但没有找到正常的答案。 anybode可以帮助我吗?

0 个答案:

没有答案