Skip to content

Instantly share code, notes, and snippets.

@udonchan
Created December 8, 2010 13:05
Show Gist options
  • Save udonchan/733257 to your computer and use it in GitHub Desktop.
Save udonchan/733257 to your computer and use it in GitHub Desktop.
食材の一覧をニコニコなんとかから取得
#!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