JANコードで商品検索
http://developer.yahoo.co.jp/webapi/shopping/shopping/v1/itemsearch.html
Yahoo!ショッピングのAPIを利用してJANコードを用いて商品の情報(今回は書名とURL)を手に入れてみる。
市販のバーコードリーダーを使ってそこいらにあった本のJANコードを読み込み、txtファイルに保存済み。XMLのパースにはBeautifulSoupを使ってみた。
from BeautifulSoup import BeautifulSoup import urllib2 op = urllib2.build_opener() appid = 'your id' apiurl = 'http://shopping.yahooapis.jp/ShoppingWebService/V1/itemSearch?appid=<%s>&jan=' % (appid) input_file = 'jancode.txt' jancode_list = open(input_file).read().split('\n') list_size = len(jancode_list) for i in range(list_size): url = apiurl + jancode_list[i] xml = op.open(url).read() soup = BeautifulSoup(xml) book_name = soup.find('name') book_url = soup.find('url') if (book_name == None): print 'None' else: print book_name.string print book_url.string
・実行結果
C++とJavaでつくるニューラルネットワーク [本]
http://store.shopping.yahoo.co.jp/7andy/32076462.html
Pythonクックブック [本]
http://store.shopping.yahoo.co.jp/7andy/31911498.html
ひと目でわかるMicrosoft Visual C++ 2008アプリケーション開発入門 [本]
http://store.shopping.yahoo.co.jp/7andy/32042365.html
AmazonのAPIと比べるとYahoo!ショッピングAPIは貧弱かもしれんね。