Python encapsulation API method for searching lazada product list data based on keywords

To get the product list through lazada's API, you can use the interface provided by the lazada open platform. The following is an example implemented using the PHP programming language to show how to obtain a product list through the lazada open platform API:

First, make sure you have registered as a developer of the lazada open platform, and create an application to obtain the required App Key and App Secret.

Then, you need to import the corresponding HTTP request library, such as Apache HttpClient or OkHttp. In this example, we use Apache HttpClient to send GET requests.

Public parameters:

name type must describe
key String yes Call key (must be spliced ​​in the URL in GET mode, demo address )
secret String yes call key
api_name String yes API interface name (included in the request address) [item_search, item_get, item_search_shop, etc.]
cache String no [yes, no] The default is yes, the cached data will be called, and the speed is relatively fast
result_type String no [json,jsonu,xml,serialize,var_export] returns the data format, the default is json, and the content output by jsonu can be read directly in Chinese
lang String no [cn,en,ru] translation language, default cn Simplified Chinese
version String no API version (copy Taobaoapi2014 to get API SDK file)

Request example (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.xxxx.cn/lazada/item_search/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&q=shoe&start_price=&end_price=&page=1&page_size=40&nation=co.th"
headers = {
    "Accept-Encoding": "gzip",
    "Connection": "close"
}
if __name__ == "__main__":
    r = requests.get(url, headers=headers)
    json_obj = r.json()
    print(json_obj)

In the above example, the API data of the lazada product list is obtained by sending HTTP/POST/GET requests, and then the returned JSON data is parsed into the corresponding data structure for further processing and use. Please note that in actual situations, you also need to construct requests, handle exceptions and other implementation details according to lazada's API documents and requirements.

Guess you like

Origin blog.csdn.net/G171104/article/details/131901790