要接入淘宝taobao评论数据,你需要先注册一个API账号并获取相应的ApiKey和ApiSecret。接下来,你可以使用Python的requests库来调用API接口。
以下是一个示例代码:
# coding:utf-8
"""
Compatible for python2.x and python3.x
requirement: pip install requests
"""
from __future__ import print_function
import requests
# 请求示例 url 默认请求参数已经做URL编码
url = "https://taobao/item_review/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=600530677643&data=&page=1"
headers = {
"Accept-Encoding": "gzip",
"Connection": "close"
}
if __name__ == "__main__":
r = requests.get(url, headers=headers)
json_obj = r.json()
print(json_obj)
请将api_key
和api_secret
替换为你注册获取的ApiKey和ApiSecret。
API接口响应示例
{
"items": {
"totalpage": "1",
"total_results": "2",
"page_size": 2,
"page": "1",
"item": [
{
"rate_content": "此用户没有填写评价。",
"rate_date": "2022-08-28",
"pics": [],
"display_user_nick": "w**8",
"auction_sku": "颜色分类:黑色【内里:超细纤维】;尺码:37",
"add_feedback": null,
"add_feedback_images": null,
"create_time_interval": null,
"rate_id": "1185790146502",
"user_star_pic": "https://img.alicdn.com/imgextra/i3/O1CN01PIYxrZ22FGrmiDphN_!!6000000007090-2-tps-92-45.png"
},
{
"rate_content": "太漂亮了 本来买的时候犹豫很久很久很久 从来没有买过黄色的 觉得不好配衣服也觉得图片一般 犹豫了有一天终于下定决心去买一个试试 结果太太太太让我惊喜了 太漂亮了 很亮鞋子特别舒服 我买的大一点 也很舒服 还挺好配衣服的 后悔就买一双了 现在我家都是她家的鞋子了 绝对的YYDS",
"rate_date": "2022-08-23",
"pics": [],
"display_user_nick": "梦**1",
"auction_sku": "颜色分类:黄色【内里:超细纤维】;尺码:36",
"add_feedback": null,
"add_feedback_images": null,
"create_time_interval": null,
"rate_id": "1184973493639",
"user_star_pic": "https://img.alicdn.com/imgextra/i4/O1CN019QZnaG1U1LtUAPn6e_!!6000000002457-2-tps-92-45.png"
}
],
"_ddf": "cdy"
},
"secache": "c8bde0fb0758d449f9b07cca295d4b61",
"secache_time": 1714966359,
"secache_date": "2024-05-06 11:32:39",
"translate_status": "",
"translate_time": 0,
"language": {
"default_lang": "cn",
"current_lang": "cn"
},
"error": "",
"reason": "",
"error_code": "0000"