Skip to content

Instantly share code, notes, and snippets.

@honasassa
Created May 15, 2014 03:15
Show Gist options
  • Save honasassa/637f8bbba681f6b30c09 to your computer and use it in GitHub Desktop.
Save honasassa/637f8bbba681f6b30c09 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mechanize'
require 'open-uri'
a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
page = a.get("http://tumblr.com/login")
form = page.forms[1]
form['user[email]'] = "email"
form['user[password]'] = "pass"
a.submit form
base_page = 1399993000
skip_num = 500
(0..500).each do |i|
page = base_page - i * skip_num
puts page
page = a.get("http://www.tumblr.com/tagged/cosplay?before=" + page.to_s)
page.links.each do |link|
uri = link.uri.to_s
if uri.include? ".png" or uri.include? ".jpg" or uri.include? ".jpeg" or uri.include? ".gif"
begin
open(uri) {|f|
filename = uri.to_s.gsub(/[\/:]+/, "")
puts filename
File.open(filename, "wb") do |file|
file.puts f.read
end
}
rescue
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment