Skip to content

Instantly share code, notes, and snippets.

@nekoTheShadow
Last active August 29, 2015 14:13
Show Gist options
  • Save nekoTheShadow/fa3d4a9fabfdd93e0ba5 to your computer and use it in GitHub Desktop.
Save nekoTheShadow/fa3d4a9fabfdd93e0ba5 to your computer and use it in GitHub Desktop.
require "net/http"
require "json"
def httpPost(url,data)
uri = URI.parse(url)
http = Net::HTTP.start(uri.host)
return http.post(uri.path,data).body
end
json = {
query: "結月ゆかり実況プレイ",
service: ["video"],
search: ["tags_exact"],
join: ["cmsid","title","view_counter"],
sort_by: "view_counter",
size: 30,
issuer: "__your_application_name__"
}.to_json
url = "http://api.search.nicovideo.jp/api/snapshot/"
res = httpPost(url,json)
# 出力を整えるために正規表現を利用する。
puts res.scan(/\{"_rowid":.*?\}/)
# なお動画タイトルのみを出力したい場合は次のようにする。
# res.scan(/"title":".*?"/).each{|str| puts str.match(/("title":)(".*?")/)[2]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment