淘宝商品列表数据接口是淘宝提供的一种可以获取淘宝商品信息的接口。通过该接口,可以获取到具有一定规则的商品信息,例如按照价格排序、按照销量排序等。接口返回的数据格式为JSON格式,可以方便地处理数据。
我们可以通过调用淘宝提供的API获取请求key和secret,使用GET方法,传入必要的参数,获取返回的JSON格式数据。其中必须传入的参数包括app_key、method、session、timestamp、v、sign等参数。
taobao.item_search-按关键字搜索淘宝商品接口代码教程
1.请求方式:HTTP POST GET
2.公共参数:
名称 |
类型 |
必须 |
描述 |
key |
String |
是 |
调用key(必须以GET方式拼接在URL中,查看调用演示) |
secret |
String |
是 |
调用密钥 |
api_name |
String |
是 |
API接口名称(包括在请求地址中)[item_search,item_get,item_search_shop等] |
cache |
String |
否 |
[yes,no]默认yes,将调用缓存的数据,速度比较快 |
result_type |
String |
否 |
[json,jsonu,xml,serialize,var_export]返回数据格式,默认为json,jsonu输出的内容中文可以直接阅读 |
lang |
String |
否 |
[cn,en,ru]翻译语言,默认cn简体中文 |
version |
String |
否 |
API版本 |
3.请求参数:
请求参数:q=女装&start_price=0&end_price=0&page=1&cat=0&discount_notallow=&sort=&page_size=&seller_info=&nick=&ppath=&imgid=&filter=
参数说明:q:搜索关键字
cat:分类ID
start_price:开始价格
end_price:结束价格
sort:排序[bid,_bid,bid2,_bid2,_sale,_credit]
(bid:总价,bid2:商品价格,sale:销量,credit信用,加_前缀为从大到小排序)
4.请求示例,支持高并发(CURL、PHP 、PHPsdk 、Java 、C# 、Python...)
# 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://api-gw.xxxx.cn/taobao/item_search/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&q=女装&start_price=0&end_price=0&page=1&cat=0&discount_only=&sort=&page_size=&seller_info=&nick=&ppath=
headers = {
"Accept-Encoding": "gzip",
"Connection": "close"
}
if __name__ == "__main__":
r = requests.get(url, headers=headers)
json_obj = r.json()
print(json_obj)
5.响应参数
以上为淘宝天猫商品列表的数据采集封装教程,希望能够帮助到有需要的朋友。