Created
December 8, 2010 13:05
-
-
Save udonchan/733257 to your computer and use it in GitHub Desktop.
食材の一覧をニコニコなんとかから取得
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
#!ruby | |
# -*- coding: utf-8 -*- | |
require 'uri' | |
require 'open-uri' | |
require 'rubygems' | |
require 'hpricot' | |
$KCODE = 'u' | |
class Syokuzai | |
attr_reader :list | |
def initialize | |
@list = Hpricot(open(URI.encode("http://dic.nicovideo.jp/a/食材の一覧"), 'User-Agent' => 'shokuzai_bot').read.delete("\n")).search("table[1]/tbody/tr/td/ul/li/a").map do |i| | |
i.inner_html.gsub(/<\/?[^>]*>/, "").sub(/(\*)$/, "") | |
end | |
end | |
def random_shokuzai | |
@list[rand(@list.size-1)] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment