Created
August 11, 2010 17:25
-
-
Save udonchan/519347 to your computer and use it in GitHub Desktop.
behoimi.org ぶっこ抜き
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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