Skip to content

Instantly share code, notes, and snippets.

@supermomonga
Created April 7, 2013 02:35
Show Gist options
  • Save supermomonga/5328654 to your computer and use it in GitHub Desktop.
Save supermomonga/5328654 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
require 'net/http'
require 'nokogiri'
class Hulu
def self.search query = ''
# http://www2.hulu.jp/search/suggest_html?query=moge&pgid=8&locale=ja
uri = URI 'http://www2.hulu.jp/search/suggest_html'
useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31'
params = {
query: query,
pgid: 8,
locale: 'ja'
}
uri.query = URI.encode_www_form params
http = Net::HTTP.new uri.host, uri.port
res = http.request Net::HTTP::Get.new(uri.request_uri, { 'User-Agent' => useragent })
p res.code
if res.code == '200'
p res.body
d = Nokogiri::HTML res.body
list = d.css('li[class=autocomplete_item]').map do |e|
e.content
end
list
else
''
end
end
end
h = Hulu.search '犬神家'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment