Created
April 7, 2013 02:35
-
-
Save supermomonga/5328654 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
# -*- 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