谁能帮助我使用 Ruby 抓取 Amazon Products API?
Posted
技术标签:
【中文标题】谁能帮助我使用 Ruby 抓取 Amazon Products API?【英文标题】:Can anyone help me scrape the Amazon Products API using Ruby? 【发布时间】:2011-01-15 09:57:25 【问题描述】:我正在使用amazon-product-advertising-api gem 并关注example code 来尝试获取音乐专辑数据。
我的代码如下:
post '/mash' do
username = params[:username]
user = Scrobbler::User.new(username)
@recommendations = user.recommendations
@urls =
@recommendations.each do |t|
lookup = AmazonProductAdvertisingApi::Operations::Item::ItemSearch.new(t.name, search_index = "Music", region = :uk)
lookup.run
if lookup.is_valid
title = lookup.response.items.first.item_attributes.title
url = lookup.response.items.first.detail_page_url
@urls[title] = url
end
end
haml :results
end
但是,我收到以下错误:
NoMethodError at /mash
undefined method `item_attributes' for nil:NilClass
当我执行put lookup.response.items.first
时,我收到以下错误/输出:
TypeError at /mash
#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1b80e38 @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1b80d34 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1b7eca0 @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB001J66K1M%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1M">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1b7ec14 @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B001J66K1M%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1M">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1b7eb60 @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B001J66K1M%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1M">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1b7eaac @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B001J66K1M%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1M">]>, @detail_page_url="http://www.amazon.co.uk/Idle-Forest-Chit-Chat-Kinny/dp/B001J66K1M%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB001J66K1M", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1b7f81c @artist="Kinny", @manufacturer="Tru Thoughts", @title="Idle Forest of Chit Chat", @product_group="Music", @contained_elements=[]>, @asin="B001J66K1M">
我认为这意味着那里有我可以访问的数据。
完整的put lookup.response.items
显示:
TypeError at /mash
#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a8e4e4 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a8cf68 @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a8ce64 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a8add0 @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB001J66K1M%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1M">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a8ad44 @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B001J66K1M%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1M">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a8ac90 @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B001J66K1M%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1M">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a8abdc @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B001J66K1M%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1M">]>, @detail_page_url="http://www.amazon.co.uk/Idle-Forest-Chit-Chat-Kinny/dp/B001J66K1M%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB001J66K1M", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a8b94c @artist="Kinny", @manufacturer="Tru Thoughts", @title="Idle Forest of Chit Chat", @product_group="Music", @contained_elements=[]>, @asin="B001J66K1M">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a86dac @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a86ca8 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a84c14 @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB0008G2FZO%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2FZO">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a84b88 @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B0008G2FZO%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2FZO">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a84ad4 @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B0008G2FZO%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2FZO">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a84a20 @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B0008G2FZO%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2FZO">]>, @detail_page_url="http://www.amazon.co.uk/Forgetting-Remember-Kinny-Horne/dp/B0008G2FZO%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0008G2FZO", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a85790 @artist="Kinny & Horne", @manufacturer="Tru Thoughts", @title="Forgetting to Remember", @product_group="Music", @contained_elements=[]>, @asin="B0008G2FZO">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a80bf0 @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a80aec @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7ea58 @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB000AMY0O0%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000AMY0O0">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7e9cc @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B000AMY0O0%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000AMY0O0">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7e918 @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B000AMY0O0%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000AMY0O0">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7e864 @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B000AMY0O0%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000AMY0O0">]>, @detail_page_url="http://www.amazon.co.uk/Us-Fire-VINYL-Kinny-Horne/dp/B000AMY0O0%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000AMY0O0", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7f5d4 @artist="Kinny & Horne", @manufacturer="Tru Thoughts", @title="Us on Fire [12\" VINYL]", @product_group="Music", @contained_elements=[]>, @asin="B000AMY0O0">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7aa34 @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7a930 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7889c @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB0008G2FZ4%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2FZ4">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a78810 @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B0008G2FZ4%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2FZ4">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7875c @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B0008G2FZ4%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2FZ4">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a786a8 @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B0008G2FZ4%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2FZ4">]>, @detail_page_url="http://www.amazon.co.uk/Why-Me-VINYL-Kinny-Horne/dp/B0008G2FZ4%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0008G2FZ4", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a79418 @artist="Kinny & Horne", @manufacturer="Tru Thoughts", @title="Why Me [7\" VINYL]", @product_group="Music", @contained_elements=[]>, @asin="B0008G2FZ4">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a74878 @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a74774 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a726e0 @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB001J66K1C%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1C">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a72654 @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B001J66K1C%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1C">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a725a0 @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B001J66K1C%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1C">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a724ec @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B001J66K1C%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB001J66K1C">]>, @detail_page_url="http://www.amazon.co.uk/Enough-Said-7-VINYL-Kinny/dp/B001J66K1C%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB001J66K1C", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a7325c @artist="Kinny", @manufacturer="Tru Thoughts", @title="Enough Said [7\" VINYL]", @product_group="Music", @contained_elements=[]>, @asin="B001J66K1C">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a6e6bc @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a6e5b8 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a6c524 @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB0008G2G0I%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2G0I">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a6c498 @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B0008G2G0I%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2G0I">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a6c3e4 @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B0008G2G0I%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2G0I">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a6c330 @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B0008G2G0I%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB0008G2G0I">]>, @detail_page_url="http://www.amazon.co.uk/Forgetting-Remember-VINYL-Kinny-Horne/dp/B0008G2G0I%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0008G2G0I", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a6d0a0 @artist="Kinny & Horne", @manufacturer="Tru Thoughts", @title="Forgetting to Remember [VINYL]", @product_group="Music", @contained_elements=[]>, @asin="B0008G2G0I">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a68500 @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a683fc @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a66368 @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB000N0LE0W%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000N0LE0W">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a662dc @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B000N0LE0W%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000N0LE0W">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a66228 @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B000N0LE0W%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000N0LE0W">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a66174 @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B000N0LE0W%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000N0LE0W">]>, @detail_page_url="http://www.amazon.co.uk/Forgetting-Remember-Kinny-Horne/dp/B000N0LE0W%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000N0LE0W", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a66ee4 @artist="Kinny & Horne", @manufacturer="Tru Thoughts", @title="Forgetting to Remember", @product_group="Music", @contained_elements=[]>, @asin="B000N0LE0W">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a62344 @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a62240 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a601ac @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB000CAEYEQ%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000CAEYEQ">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a60120 @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B000CAEYEQ%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000CAEYEQ">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a6006c @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B000CAEYEQ%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000CAEYEQ">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a5ffb8 @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B000CAEYEQ%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000CAEYEQ">]>, @detail_page_url="http://www.amazon.co.uk/Rod-Kinny-EP/dp/B000CAEYEQ%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000CAEYEQ", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a60d28 @artist="Rod Kinny", @manufacturer="Import (Megaphon Importservice)", @title="The Rod Kinny EP", @product_group="Music", @contained_elements=[]>, @asin="B000CAEYEQ">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a5c188 @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a5c084 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a59ff0 @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB000E9X33I%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000E9X33I">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a59f64 @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B000E9X33I%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000E9X33I">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a59eb0 @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B000E9X33I%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000E9X33I">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a59dfc @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B000E9X33I%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000E9X33I">]>, @detail_page_url="http://www.amazon.co.uk/Us-Fire-VINYL-Kinny-Horne/dp/B000E9X33I%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000E9X33I", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a5ab6c @artist="Kinny & Horne", @manufacturer="Tru Thoughts", @title="Us on Fire [12\" VINYL]", @product_group="Music", @contained_elements=[]>, @asin="B000E9X33I">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a55fcc @item_links=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1a55ec8 @contained_elements=[#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1af7034 @description="Add To Wishlist", @contained_elements=[], @url="http://www.amazon.co.uk/gp/registry/wishlist/add-item.html%3Fasin.0%3DB000CA74KM%26SubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000CA74KM">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1af9adc @description="Tell A Friend", @contained_elements=[], @url="http://www.amazon.co.uk/gp/pdp/taf/B000CA74KM%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000CA74KM">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1afd358 @description="All Customer Reviews", @contained_elements=[], @url="http://www.amazon.co.uk/review/product/B000CA74KM%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000CA74KM">, #<AmazonProductAdvertisingApi::Operations::Base::Element:0x1b00918 @description="All Offers", @contained_elements=[], @url="http://www.amazon.co.uk/gp/offer-listing/B000CA74KM%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB000CA74KM">]>, @detail_page_url="http://www.amazon.co.uk/Open-Up-the-Letter/dp/B000CA74KM%3FSubscriptionId%3D1V38YK4WRF7GKYKXBSR2%26tag%3Dwhishapo-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000CA74KM", @contained_elements=[], @item_attributes=#<AmazonProductAdvertisingApi::Operations::Base::Element:0x1abe9c8 @manufacturer="Simon Kinny-Lewis", @title="Open Up the Letter", @product_group="Music", @contained_elements=[]>, @asin="B000CA74KM">]>
如果我尝试put title
,我会收到以下错误:
ArgumentError at /mash
tried to create Proc object without a block
raise title
似乎知道发生了什么:
RuntimeError at /mash
Idle Forest of Chit Chat
如果 put/raise url 也会发生同样的事情(尽管显然是 URL 不是标题)。
不幸的是,我的 Ruby 知识正处于学习阶段,我不知道现在发生了什么。任何帮助将不胜感激。
(如果有帮助,这是 Sinatra 应用程序的一部分...)
【问题讨论】:
【参考方案1】:在我看来,您的“lookup.response.items.first”。正在返回一个 nil 对象,因此您需要首先验证至少有一个项目供您查找
【讨论】:
当我'放'它并得到一个关于它的事实表明它是一个对象?或者红宝石不是那样工作的?以上是关于谁能帮助我使用 Ruby 抓取 Amazon Products API?的主要内容,如果未能解决你的问题,请参考以下文章
Ruby - Songkick api - 在 events.location() 查询方面需要帮助 [关闭]
我可以将 Ruby 版本 2.1.2 与 Amazon Elastic Beanstalk 一起使用吗?