代码已上传 https://github.com/jevy146/keepa
1.https://keepa.com/#! 这个是keepa的官网,首先你需要注册购买其服务。相对于他能提供的亚马逊的大量数据,这些钱花的超值。 2.这里以日本站的数据获取为例。 https://www.amazon.co.jp/dp/B003G357L0 在这个插件中你可以获取历史的排名以及价格、评论的变化情况。 3.这里使用的是Python调用其API的数据,keepa的首席执行官给的开源文档是java写的,,果然java才是最强的编程语言。亚马逊后台给的API接口用的是php,java和.Net。 这里放出来的是亚纳逊的官方API开发文档接口:欢迎大家参与交流。 http://docs.developer.amazonservices.com/zh_CN/orders/2013-09-01/Orders_GetOrder.html 我收集的亚马逊对接api的链接,也有大佬用Python封装了接口
1. http://docs.developer.amazonservices.com/zh_CN/fba_outbound/FBAOutbound_Overview.html官方
2.https://blog.csdn.net/zhou_xtao/article/details/96109682
3.https://github.com/jevy146/amazon-demo 使用java调用亚马逊的API数据
4.https://github.com/mystudytime/easy-amazon-advertising 亚马逊对接广告数据
5.https://www.crifan.com/python_amazon_aws_api_lib_framework/ 调用api文档
4.进入正题: 这个是keepa官方给出的api接口代码。 https://github.com/keepacom/api_backend/ 按照正常的操作:传入参数,相应的结果如下链接所示。这里作为java仅能看懂的菜鸟不作展开。 https://keepa.com/#!discuss/t/product-object/116 5.下面介绍以为Python语言的福音。有为大佬带着拯救世界的步伐过来了。 https://github.com/akaszynski/keepa 看到这个开源的代码,我的眼泪就要流下来了,好吧! 我们pip install keepa 安装这个包。包不算大。 查看其源码的,主要用的这个类和 parse_csv这个函数。 6.那我们就按照大佬的代码走一遍。 首先去官网拿到你的api的钥匙,原谅我这里打上马赛克。。一个月15刀。 https://keepa.com/#!api
7.这里由于用的是日文,我就将作者的代码稍微修改了一下。已知大佬用的是Python中的matplotlib画图。 源码里面有。那就好办了。 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200425163420222.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzM1MTkzNQ==,size_16,color_FFFFFF,t_70)
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
import keepa
#https://keepa.com/#!api keepa数据的api
# enter real access key here
accesskey = '*****输入你自己的api钥匙******'
#这里可以添加参数,后面再说。
api = keepa.Keepa(accesskey)
# Single ASIN query
products = api.query('B003G357L0',domain='JP') # returns list of product data
keepa.plot_product(products[0])
运行要花一些时间。 运行结果:这里我分段截图
这里我补充一下。 当你发送 api.query(‘B003G357L0’,domain=‘JP’)的请求时,keepa响应的结结果products是一个列表长度为1,这里我怎么说呢,我将这个数据保存到本地:
file=open('./out.txt','w',encoding="utf-8")
file.write(str(products[0]))
file.close()
这里获取products[0]的数据,里面就是一个字典了。 https://keepa.com/#!discuss/t/request-products/110/1 这里是官方给出请求参数的介绍 字典里面包含了很多信息。 这里你估计会想:我操这都是什么鬼,官方文档里面给出的我就不说了,这里说一下keepa这个包作者的思路。也就是这两个键的值 这里你不需要去解析product[‘csv’],作者是将这个解析了的,然后放到 product[‘data’]里面了。 我为啥这么说呢?我们看源码:这里作者使用parse_csv() 这个函数解析的。 我们看一下这个函数,源码我贴上来,这里传入一个列表(csv)
def parse_csv(csv, to_datetime=True, out_of_stock_as_nan=True):
"""Parses csv list from keepa into a python dictionary.
Parameters
----------
csv : list
csv list from keepa
to_datetime : bool, optional
Modifies numpy minutes to datetime.datetime values.
Default True.
out_of_stock_as_nan : bool, optional
When True, prices are NAN when price category is out of stock.
When False, prices are -0.01
Default True
Returns
-------
product_data : dict
Dictionary containing the following fields with timestamps:
AMAZON: Amazon price history
NEW: Marketplace/3rd party New price history - Amazon is
considered to be part of the marketplace as well, so if
Amazon has the overall lowest new (!) price, the
marketplace new price in the corresponding time interval
will be identical to the Amazon price (except if there is
only one marketplace offer). Shipping and Handling costs
not included!
USED: Marketplace/3rd party Used price history
SALES: Sales Rank history. Not every product has a Sales Rank.
LISTPRICE: List Price history
5 COLLECTIBLE: Collectible Price history
6 REFURBISHED: Refurbished Price history
7 NEW_FBM_SHIPPING: 3rd party (not including Amazon) New price
history including shipping costs, only fulfilled by
merchant (FBM).
8 LIGHTNING_DEAL: 3rd party (not including Amazon) New price
history including shipping costs, only fulfilled by
merchant (FBM).
9 WAREHOUSE: Amazon Warehouse Deals price history. Mostly of
used condition, rarely new.
10 NEW_FBA: Price history of the lowest 3rd party (not
including Amazon/Warehouse) New offer that is fulfilled
by Amazon
11 COUNT_NEW: New offer count history
12 COUNT_USED: Used offer count history
13 COUNT_REFURBISHED: Refurbished offer count history
14 COUNT_COLLECTIBLE: Collectible offer count history
16 RATING: The product's rating history. A rating is an
integer from 0 to 50 (e.g. 45 = 4.5 stars)
17 COUNT_REVIEWS: The product's review count history.
18 BUY_BOX_SHIPPING: The price history of the buy box. If no
offer qualified for the buy box the price has the value
-1. Including shipping costs.
19 USED_NEW_SHIPPING: "Used - Like New" price history
including shipping costs.
20 USED_VERY_GOOD_SHIPPING: "Used - Very Good" price history
including shipping costs.
21 USED_GOOD_SHIPPING: "Used - Good" price history including
shipping costs.
22 USED_ACCEPTABLE_SHIPPING: "Used - Acceptable" price history
including shipping costs.
23 COLLECTIBLE_NEW_SHIPPING: "Collectible - Like New" price
history including shipping costs.
24 COLLECTIBLE_VERY_GOOD_SHIPPING: "Collectible - Very Good"
price history including shipping costs.
25 COLLECTIBLE_GOOD_SHIPPING: "Collectible - Good" price
history including shipping costs.
26 COLLECTIBLE_ACCEPTABLE_SHIPPING: "Collectible - Acceptable"
price history including shipping costs.
27 REFURBISHED_SHIPPING: Refurbished price history including
shipping costs.
30 TRADE_IN: The trade in price history. Amazon trade-in is
not available for every locale.
31 RENT: Rental price history. Requires use of the rental
and offers parameter. Amazon Rental is only available
for Amazon US.
Notes
-----
Negative prices
"""
# https://github.com/keepacom/api_backend
# see api_backend/src/main/java/com/keepa/api/backend/structs/Product.java
# [index in csv, key name, isfloat (is price)]
indices = [[0, 'AMAZON', True],
[1, 'NEW', True],
[2, 'USED', True],
[3, 'SALES', False],
[4, 'LISTPRICE', True],
[5, 'COLLECTIBLE', True],
[6, 'REFURBISHED', True],
[7, 'NEW_FBM_SHIPPING', True],
[8, 'LIGHTNING_DEAL', True],
[9, 'WAREHOUSE', True],
[10, 'NEW_FBA', True],
[11, 'COUNT_NEW', False],
[12, 'COUNT_USED', False],
[13, 'COUNT_REFURBISHED', False],
[14, 'CollectableOffers', False],
[15, 'EXTRA_INFO_UPDATES', False],
[16, 'RATING', True],
[17, 'COUNT_REVIEWS', False],
[18, 'BUY_BOX_SHIPPING', True],
[19, 'USED_NEW_SHIPPING', True],
[20, 'USED_VERY_GOOD_SHIPPING', True],
[21, 'USED_GOOD_SHIPPING', True],
[22, 'USED_ACCEPTABLE_SHIPPING', True],
[23, 'COLLECTIBLE_NEW_SHIPPING', True],
[24, 'COLLECTIBLE_VERY_GOOD_SHIPPING', True],
[25, 'COLLECTIBLE_GOOD_SHIPPING', True],
[26, 'COLLECTIBLE_ACCEPTABLE_SHIPPING', True],
[27, 'REFURBISHED_SHIPPING', True],
[28, 'EBAY_NEW_SHIPPING', True],
[29, 'EBAY_USED_SHIPPING', True],
[30, 'TRADE_IN', True],
[31, 'RENT', False]]
product_data = {}
for ind, key, isfloat in indices:
if csv[ind]: # Check if entry it exists
if 'SHIPPING' in key: # shipping price is included
# Data goes [time0, value0, shipping0, time1, value1,
# shipping1, ...]
times = csv[ind][::3]
values = np.array(csv[ind][1::3])
values += np.array(csv[ind][2::3])
else:
# Data goes [time0, value0, time1, value1, ...]
times = csv[ind][::2]
values = np.array(csv[ind][1::2])
# Convert to float price if applicable
if isfloat:
nan_mask = values |