Skip to content

Instantly share code, notes, and snippets.

@udonchan
Created August 11, 2010 17:25
Show Gist options
  • Save udonchan/519347 to your computer and use it in GitHub Desktop.
Save udonchan/519347 to your computer and use it in GitHub Desktop.
behoimi.org ぶっこ抜き
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'open-uri'
require 'uri'
require 'rubygems'
require 'nokogiri'
class Bucko
def initialize
@root = 'http://behoimi.org'
@ua = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; rv:1.9.2.7) Gecko/20100713 Firefox/3.6.7'
end
def page_open (uri)
open(URI.encode(uri), 'User-Agent' => @ua).read
end
def get_image (uri, ref)
system "wget --user-agent=\"#{@ua}\" --referer=\"#{ref}\" \"#{uri}\""
sleep 1
end
def exec (tags, page=1)
(1..page).each do |p|
page = Nokogiri::XML(page_open("#{@root}/post/index?page=#{p}&tags=#{tags}"))
page.xpath("//span[@class=\"thumb blacklisted\"]/a/@href").each do |l|
get_image(Nokogiri::XML(page_open("#{@root}#{l}")).xpath("//a[@id=\"highres\"]/@href"), "#{@root}#{l}")
end
end
end
end
# example
# Bucko.new().exec('lenfried', 108)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment