2017-05-14 7 views
1

이 사진이 네비게이터에 표시됩니다하지만 난 점점 오류를 유지 웹 브라우저에서 작동하는 링크를 열 수 없습니다 내가 가지고있는, 지금까지 루비 : 나는이 사이트 mangafox에서 사진을 얻기 위해 노력하고

루비

오순절

require 'open-uri' 
require 'pp' 

def get_page(link) 
    page = nil 
    begin 
    page = open(link, 'User-Agent' => "Ruby/#{RUBY_VERSION}") 
    rescue Exception => e 
    puts e.class.to_s 
    puts e.message 
    end 
    return page 
end 

link = 'http://h.mfcdn.net/store/manga/9/14-116.0/compressed/Bleach-14-116[manga-rain]._manga_rain_bleach_ch116_01.jpg?token=24530ad3411b28ed7f5ef17f932e8713&ttl=1494853200' 
# tried this after researching on internet because some characters are refused in links (such as '[' or ']') 
link2 = link.gsub(/[\[\]]/) { '%%%s' % $&.ord.to_s(16) }.chomp 

pp get_page(link) 
pp get_page(link2) 

하지만이 출력을 얻을 :

URI :: InvalidURIError
나쁜 URI가 (URI하지?) :이 시도 http://h.mfcdn.net/store/manga/9/14-116.0/compressed/Bleach-14-116[manga-rain]._manga_rain_bleach_ch116_01.jpg?token=24530ad3411b28ed7f5ef17f932e8713&ttl=1494853200
전무
OpenURI :: HTTPError
403 OpenURI가 핀치에 괜찮 사용
전무

답변

2

을 금지하지만, 당신은 더 나은 인터넷 같은보다 강력한 네트워킹 라이브러리에 의해 제공 될 것입니다 : HTTP 또는 Typhoeus :

response = Typhoeus.get('http://h.mfcdn.net/store/manga/9/14-116.0/compressed/Bleach-14-116[manga-rain]._manga_rain_bleach_ch116_01.jpg?token=24530ad3411b28ed7f5ef17f932e8713&ttl=1494853200') 
response.body #=> binary image data 

(참고 : 공유하기 전에이 테스트 - 그것은 잘로드)가 감사를 완벽하게 많이 작동

+0

. 오류 처리에 대한 설명서를 살펴야합니다. –