我有一个代码:
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)
截图:
我用谷歌搜索了,但没有找到正常的答案。 anybode可以帮助我吗?