Skip to content

Instantly share code, notes, and snippets.

@takkumattsu
Created June 2, 2015 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takkumattsu/10ca0508e9f449e51940 to your computer and use it in GitHub Desktop.
Save takkumattsu/10ca0508e9f449e51940 to your computer and use it in GitHub Desktop.
http://killmebaby.tv/special_icon.html にあるキルミーベイベーのアイコンを取得し保存するスクリプト
require 'open-uri'
require 'nokogiri'
# Author:TakkuMattsu
# thanks:
# http://somethingpg.hatenablog.com/entry/20120603/1338715064
# https://gist.github.com/ejo090/4480809f0a683255803e
#
url = 'http://killmebaby.tv/special_icon.html'
charset = nil
html = open(url) do |f|
charset = f.charset
f.read
end
page = Nokogiri::HTML.parse(html, nil, charset)
ary = Array.new
page.css('img').each do |link|
if /http:\/\/aka\.saintpillia\.com\/killme\/icon\/[0-9_-]{3,}\.png/ =~ link[:src]
ary.push(link[:src])
end
end
ary.each_with_index do |url,index|
filename = "%04d.png"%index
dirname = Dir.pwd + "/" + filename
open(dirname, 'wb') do |file|
open(url) do |data|
file.write(data.read)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment