Escape/Bypass Ruby 中的 404 错误(Instagram API)
Escape/Bypass 404 error in Ruby (Instagram API)
我正在尝试让 ruby 到 escape/bypass 出现 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]
有谁知道我该如何绕过这个错误?
这是你想要的吗?
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
begin
doc = Hpricot(open(webby)).to_s
jpgstart = '<meta property=\"og:image\" content=\"'
jpgstop = '" />'
jpglink = doc[/#{jpgstart}(.*?)#{jpgstop}/m, 1]
print jpglink
rescue OpenURI::HTTPError
# do nothing. bypass error.
end
我正在尝试让 ruby 到 escape/bypass 出现 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]
有谁知道我该如何绕过这个错误?
这是你想要的吗?
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
begin
doc = Hpricot(open(webby)).to_s
jpgstart = '<meta property=\"og:image\" content=\"'
jpgstop = '" />'
jpglink = doc[/#{jpgstart}(.*?)#{jpgstop}/m, 1]
print jpglink
rescue OpenURI::HTTPError
# do nothing. bypass error.
end