Skip to content

Instantly share code, notes, and snippets.

@soramugi
Created April 21, 2014 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soramugi/11132301 to your computer and use it in GitHub Desktop.
Save soramugi/11132301 to your computer and use it in GitHub Desktop.
amazon本の人気ランキング取得
require 'amazon/ecs'
Amazon::Ecs.options = {
AWS_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
AWS_secret_key: ENV['AWS_SECRET_KEY'],
associate_tag: ENV['ASSOCIATE_TAG'],
}
# 本の人気ランキング取得
res = Amazon::Ecs.item_search(
'salesrank', # typeで指定してるパラメータの引数になる
type: :sort, # typeパラメータでKeyword指定のパラメータを削除して sort: 'salesrank' になるようにしてる
search_index: 'Books',
browse_node: 465610, # 本のnode
power: 'binding:not kindle', # kindle除外
country: 'jp',
response_group: 'ItemAttributes,OfferSummary', # 取得出来るアイテムの基本情報と価格
item_page: 1, # 1ページ目
)
p res.error
# 検索結果で取れるアイテム数
p res.total_results
# 最大10件
res.items.each do |item|
item_attributes = item.get_element('ItemAttributes')
title = item_attributes.get_unescaped('Title')
jan = item_attributes.get_unescaped('EAN')
offer_summary = item.get_element('OfferSummary')
new_price = offer_summary.get_unescaped('LowestNewPrice/Amount') rescue nil
used_price = offer_summary.get_unescaped('LowestUsedPrice/Amount') rescue nil
p "jan: #{jan} new_price: #{new_price} used_price: #{used_price} title: #{title}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment