我有一個網站(www.7bks.com),用戶可以在其中創建書目列表。目前相當簡單。我已經在使用亞馬遜API將圖書信息,圖像等引入網站。使用Amazon BrowseNodes API做一些有意義的事
我想要做的是以某種方式使用Amazon API撤回類別和/或標籤數據,以創建某種方式在我的網站上瀏覽列表。不幸的是,標籤API方法已停用。
最有可能的候選人是Amazon API的BrowseNodes方法(http://docs.amazonwebservices.com/AWSEcommerceService/2005-10-05/ApiReference/BrowseNodesResponseGroup.html),但從此調用返回的數據很漂亮無意義的,我希望我們能夠將我們的頭腦融合在一起,並弄清楚如何理解它。
這裏是一個谷歌電子表格,告訴你我得到的數據的種類。我通過BrowseNodes API拿起一個樣品列表(http://www.7bks.com/list/549002),並跑了三本書:
縱觀名單,你不要一個人需要知道這些書是什麼,才能看到它可能是關於科幻和幻想的列表。這主要是因爲眼睛擅長丟棄諸如「定製商店」和「小說完整」等無意義的類別。
我嘗試了對類別列表進行重複刪除,或者只查看所有3本書出現的類別,但它仍然是相當垃圾的數據。我很想知道如何將這些數據轉化爲對用戶有意義的內容。
我到目前爲止最好的想法是掃描數據並匹配硬編碼列表。因此,像:
如果計數(「科幻奇幻&」)> 3,那麼列表是科幻 如果計數(「企業財務&法」)> 3,那麼列表是商業
等
雖然這是非常僵化的,理想情況下,我希望構建一些更靈活/更強大的東西。
歡迎任何建議。
我認爲這是一個高層次的問題,所以不應該受到如何調用API,但參考我使用Python/Appengine/Webapp的影響。
感謝
湯姆
UPDATE反對臺頭撞多後,我設法解決這個問題,這讓我滿意。這並不複雜,但我一起砍了一些我想要的python代碼。我歡迎任何人改進我的代碼或提供建議。
基本上,代碼的基礎邏輯是這樣的: 1)在XML樹中,節點的底部節點(書本>科目)是對本書實際內容的最好猜測。例如。爲此:http://www.amazon.co.uk/Surface-Detail-Iain-M-Banks/dp/1841498939/它返回「科幻小說」。答對了。 2)通常情況下,通過限制自己開始的那些結果(書>主題),會拋出很多很好的信息。因此, 3)我嘗試獲取類似書籍的列表,並將類別從它們上拉下來,如果失敗了,我只會將類別分配給原始圖書。
#takes as input the xml output of the amazon api browsenodes call
def getcategories(xml):
#fetches the names of all the nodes, stores them in a list
categories = []
for book in xml.getElementsByTagName('BrowseNode'):
category = get_text(book,'Name')
categories.append(category)
#turn the one list into a series of individual lists
#each individual list should be a particular tree from browsenode
#each list will end 'Books'
#the first item in the list should be the bottom of the tree
taglists = []
while 'Books' in categories:
find = categories.index('Books') + 1
list = categories[:find]
taglists.append(list)
for word in list:
categories.remove(word)
#now, we only return the first item from a list which contains 'Subjects'
final = []
for tagset in taglists:
while 'Subjects' in tagset:
final.append(tagset[0])
tagset.pop(tagset.index('Subjects'))
return final
class Browsenodes(webapp.RequestHandler):
def get(self):
#get the asin of the target book
asin = self.request.get('term')
if book_title:
#fetch the amazon key
api = API(AWS_KEY, SECRET_KEY, 'uk', processor=minidom_response_parser)
try:
#try getting a list of similar books - note the response group set to browsenodes
result = api.similarity_lookup(asin, ResponseGroup='BrowseNodes')
except:
#there aren't always a list of similar books, so as a failsafe just get the book I wanted.
result = api.item_lookup(asin, ResponseGroup='BrowseNodes')
final = getcategories(result)
#turn it into a set to de-dupe multiple listings of the same category
self.response.out.write(set(final))
爲了給你輸出的味道:
書: http://www.amazon.co.uk/Surface-Detail-Iain-M-Banks/dp/1841498939/
標籤: 當代小說 產品
也許最好給你的代碼解釋如下 Space Opera 科幻小說
http://www.amazon.co.uk/Godel-Escher-Bach-Eternal-anniversary/dp/0140289208/ 心理學 數學 數理邏輯 一般AAS 熱門數學 科學史,技術&醫療 藝術&音樂 心靈 亞馬遜 數學 建築哲學&邏輯 當代哲學:1900- 邏輯 經典 物理 形而上學 物理哲學 一般 技術 代數數論 人工智能 科學史
http://www.amazon.co.uk/Flatland-Romance-Dimensions-Dover-Thrift/dp/048627263X/ 當代小說 哲學數學 一般AAS 熱門數學 哲學 科學,技術&醫療 哲學思維 科幻 數學代數數論 產品 經典 形而上學&有遠見 神話&童話 拓撲一般 主題 一般 理論方法 形而上學 人工智能 科學史
http://www.amazon.co.uk/Victoria-Condor-Books-Knut-Hamsun/dp/0285647598/ 當代小說 進口圖書 心理 一般AAS 經典 Short Storie s