【发布时间】:2017-05-14 15:05:49
【问题描述】:
我正在尝试从网站 mangafox 获取图片,图片显示在导航器中,但我不断收到 Ruby 错误
到目前为止,我已经尝试过:
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禁止
无
【问题讨论】:
标签: ruby web-scraping open-uri