Skip to content

Instantly share code, notes, and snippets.

@felinebabies
Created August 5, 2017 10:33
Show Gist options
  • Select an option

  • Save felinebabies/7b91b2c31b8eebae5b314f217729f7eb to your computer and use it in GitHub Desktop.

Select an option

Save felinebabies/7b91b2c31b8eebae5b314f217729f7eb to your computer and use it in GitHub Desktop.
ねこのイラストを一括ダウンロードしてくるやつ
# coding: utf-8
require "nokogiri"
require "open-uri"
require "uri"
INDEXPAGEURL = "http://illustrain.com/?cat=19"
SAVEDIR = "./download"
html = open(INDEXPAGEURL).read
doc = Nokogiri::HTML(html, INDEXPAGEURL)
puts doc.title
pagelistarr = doc.css(".thumb-post-lists li a").map do |item|
item.attr("href")
end
puts pagelistarr
pagelistarr.each do |url|
html = open(url).read
doc = Nokogiri::HTML(html, url)
illusturl = doc.css(".bt-download a").attr("href")
illustdata = open(illusturl).read
filename = File.basename(illusturl)
savepath = File.join(SAVEDIR, filename)
open(savepath, "w+b") do |out|
out.write(illustdata)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment