8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Amazon APIによる食品データの取得 (Python)

Last updated at Posted at 2015-07-01

概要

Amazonのapiを用いて,食品データを取得する (python).

ステップ1: Amazon APIを使えるようにする

Amazon APIを使えるようにして、ある程度使い方を覚える。
参考URL
http://www.ajaxtower.jp/ecs/

ステップ2: タイムスタンプ

クエリにタイムスタンプを加える.
フォーマットは以下,

import time
Time = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
url_qs.append(("Timestamp", [Time]))
url_qs = sorted(url_qs)

ステップ3: Signature生成

まず,amazonからもらった秘密キーを使って,sha-256規格でハッシュを生成する.

import hmac, hashlib
hmac_digest = hmac.new(array['secret_key'], req, hashlib.sha256).digest()

生成されたハッシュをbase64にエンコードし,クオートすればsinatureの完成

import base64
base64_encoded = base64.b64encode(hmac_digest) # base64
signature = urllib2.quote(base64_encoded)

ステップ4: xmlをパースして抽出

from pyquery import PyQuery as pq
from lxml import etree

a = pq(etree.fromstring(test), parser='xml')
        f = a('ns|Feature', namespaces={"ns":"http://webservices.amazon.com/AWSECommerceService/2011-08-01"}).text())

原材料は,Featureに格納されている

8
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?