将书籍作者分为小说与非小说
为了我个人的需要,我有大约300位不同书籍的作者(全名)。我想把这个名单分成“小说作者”和“非小说作者”。如果一个作者同时写这两种类型的书,那就看他写哪种类型的书多,按照多数来决定。
我查看了亚马逊的产品搜索API:我可以通过作者来搜索(在Python中使用),但是没有办法找到书籍的类别(小说和其他类型):
>>> node = api.item_search('Books', Author='Richard Dawkins')
>>> for book in node.Items.Item:
... print book.ItemAttributes.Title
我有哪些选择?我更倾向于用Python来实现这个。
3 个回答
0
经过一段时间对亚马逊API的研究,发现他们并没有提供你想要的信息。
在他们的文档中没有提到那种类型的分类,而且如果你把API发送给你的数据进行序列化,根本找不到“虚构”或“非虚构”这样的分类。
你可以用这个方法打印出一个漂亮的XML字符串(你可能想把它保存到一个文件里,方便阅读),里面包含了API发送的所有内容。
from lxml import etree
node = api.item_search('Books', Author='Richard Dawkins')
print etree.tostring(node, pretty_print=True)
2
你有没有看看这个BrowseNodes
?对我来说(我之前没有用过这个API),BrowseNodes
好像是对应亚马逊的产品分类。也许你能在那找到更多的信息。
4
你可以试试另一个服务 - Google 图书搜索 API。如果你想用 Python,可以看看 gdata-python-api。在它的协议中,结果数据里有一个节点 <dc:subject>
- 这可能就是你需要的内容:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
xmlns:gbs="http://schemas.google.com/books/2008"
xmlns:dc="http://purl.org/dc/terms"
xmlns:gd="http://schemas.google.com/g/2005">
<id>http://www.google.com/books/feeds/volumes</id>
<updated>2008-08-12T23:25:35.000</updated>
<!-- a loot of information here, just removed those nodes to save space.. -->
<dc:creator>Jane Austen</dc:creator>
<dc:creator>James Kinsley</dc:creator>
<dc:creator>Fiona Stafford</dc:creator>
<dc:date>2004</dc:date>
<dc:description>
If a truth universally acknowledged can shrink quite so rapidly into
the opinion of a somewhat obsessive comic character, the reader may reasonably feel ...
</dc:description>
<dc:format>382</dc:format>
<dc:identifier>8cp-Z_G42g4C</dc:identifier>
<dc:identifier>ISBN:0192802380</dc:identifier>
<dc:publisher>Oxford University Press, USA</dc:publisher>
<dc:subject>Fiction</dc:subject>
<dc:title>Pride and Prejudice</dc:title>
<dc:title>A Novel</dc:title>
</entry>
</feed>
当然,这个协议还会给你一些额外的信息,比如这本书在 Google 图书上是否可见等等。