我试图让 ruby 逃避/绕过 404 错误,但它似乎不起作用。到目前为止,这是我的代码:
require 'rubygems'
require 'simple_oauth'
require 'cloudsight'
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'open-uri'
require 'openssl'
require 'hpricot'
require 'nokogiri'
#T FILE TO JPG
webby = 'https://t.co/5h92pCmoPM'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
doc = Hpricot(open(webby)).to_s
jpgstart = '<meta property=\"og:image\" content=\"'
jpgstop = '" />'
jpglink = doc[/#{jpgstart}(.*?)#{jpgstop}/m, 1]
print jpglink
这是我得到的错误:
C:/Users/User/Desktop/test89:18: warning: already initialized constant OpenSSL::SSL::VERIFY_PEER
C:/Ruby21/lib/ruby/2.1.0/open-uri.rb:353:in `open_http': 404 NOT FOUND (OpenURI::HTTPError)
from C:/Ruby21/lib/ruby/2.1.0/open-uri.rb:724:in `buffer_open'
from C:/Ruby21/lib/ruby/2.1.0/open-uri.rb:210:in `block in open_loop'
from C:/Ruby21/lib/ruby/2.1.0/open-uri.rb:208:in `catch'
from C:/Ruby21/lib/ruby/2.1.0/open-uri.rb:208:in `open_loop'
from C:/Ruby21/lib/ruby/2.1.0/open-uri.rb:149:in `open_uri'
from C:/Ruby21/lib/ruby/2.1.0/open-uri.rb:704:in `open'
from C:/Ruby21/lib/ruby/2.1.0/open-uri.rb:34:in `open'
from C:/Users/KVadher/Desktop/test89:20:in `<main>'
[Finished in 2.7s with exit code 1]
有谁知道我如何绕过错误?