我正在尝试通过检查图片链接,访问它们并下载完整图像来从网站下载所有全分辨率图像。
我设法让它有点工作。我可以从i.imgur
获取所有链接并下载图片。不过,我想让它适用于更多网站和普通imgur
相册以及没有wget
(我现在正在使用,如下所示)。
这是我正在玩的代码(不要判断,它只是测试代码):
require 'mechanize'
require 'uri'
def get_images()
crawler = Mechanize.new
img_links = crawler.get("http://www.reddit.com/r/climbing/new/?count=25&after=t3_39qccc").links_with(href: %r{i.imgur})
return img_links
end
def download_images()
img_links = get_images()
crawler = Mechanize.new
clean_links = []
img_links.each do |link|
current_link = link.uri.to_s
unless current_link.include?("domain")
unless clean_links.include?(current_link)
clean_links << current_link
end
end
end
p clean_links
clean_links.each do |link|
system("wget -P ./images -A jpeg,jpg,bmp,gif,png #{link}")
end
end
download_images()