1, the preface

1.1. What is Taobao Customer

I believe many people have heard or come into contact with various shopping guide apps, QQ groups, wechat groups to share some taobao products coupons or other preferential information.

! [](https://p1.pstatp.com/origin/pgc-image/ed594d13a698414e9b474b028af4b790)
! [](https://p1.pstatp.com/origin/pgc-image/97a8f9c940fa4a59aa2866ff4a6e1c36)

Through these channels, users can obtain more favorable prices or receive coupons with larger denominations compared to products found on Taobao platform.

These channels are the channels that belong to taobao customers. Taobao customer is a pay-per-transaction promotion model launched by Taobao platform, usually also refers to the people who make money through this model.

A few years ago, taobao was booming, all kinds of shopping guide website, shopping guide APP and coupon QQ group, wechat group emerge in endlessly, but now it is slightly dull. Although taobao customers become dull on the swarmed Internet, it does not affect the mentality of the new crowd at all. If you search “wechat shopping guide machine” on Taobao, you can also see many businesses selling Wechat robots of Taobao:

! [](https://p1-tt-ipv6.byteimg.com/origin/pgc-image/74c1a4985cfc4354b60514ac1dbcbf95)

In fact, the main function of these wechat robots is to automatically reply to the messages of people in the group, and push some preferential commodity information regularly.

Today, we use Python, which can appear anywhere and be anywhere, to build a Taobao customer wechat robot to realize the most basic function of taobao customer shopping guide wechat robot, which can automatically reply to search and return goods in group chat.

1.2. Register as a Taobao customer

To write a Wechat robot for Taobao customers, we first need to become a Taobao customer, in order to obtain taobao customer-related preferential resources. The method is simple: register an account on Pub.alimama.com/, the promotion platform of Taobao users.

! [](https://p26-tt.byteimg.com/origin/pgc-image/37aa17dbb00f4059a40d2d7842564261)

After logging in, we can set up the promotion media in “Promotion Management” in “My Union” :

! [](https://p6-tt-ipv6.byteimg.com/origin/pgc-image/053676be0caf4870b0a72e1a81a16908)

Among them, we can add websites, APPS, shopping guides, software promotion and so on. At this point, I have added a website to the media and submitted it successfully for verification. Promotion media is a basic channel for taobao customers to promote goods, which is used to belong to different promotion places. If there is no promotion media, there is no way to create promotion places, and then it is impossible to promote Taobao customers. We can create promotion media according to their own situation, recommend the use of website promotion media.

After creating the promotion media, we also need to create a promotion bit, which is used for specific Taobao customers to promote products. Here I have created the promotion bit of the website, in which PID will be used when we call the API interface later. Please note that:

! [](https://p26-tt.byteimg.com/origin/pgc-image/4edbf121ac8a48cabf14686d459cecc7)

If there is no promotion slot, then we can click the “Selected List” button in “Alliance Products” for immediate download:

! [](https://p26-tt.byteimg.com/origin/pgc-image/cfd954f89f0843c4b92782f8d117cb23)

It will let us choose the promotion bit, at this time we can create a promotion bit:

! [](https://p1-tt-ipv6.byteimg.com/origin/pgc-image/6fb9d9b907f04241a2608ea69efcd53a)

So we get a promotion spot to promote the website.

Back to the promotion media management, after the website media we added passes the verification of Ali Mom successfully, we will get an API of the alliance cooperation website:

Click the “View” link, it will jump to the overview of the website promotion bit created by us on Ali Open Platform (promotion bit is displayed as an application on Ali Open Platform), which shows our application interface information, interface data and access API, etc. :

! [](https://p1-tt-ipv6.byteimg.com/origin/pgc-image/c1c0ffd47d5d4efcb1789604ff2d1676)

The APP Key and APP Secret in the APP certificate will be used as credentials for authentication when the API interface is called. The following functional scenarios show the API interface we have obtained: here are my applications:

  • Taobao customer base API
  • Taobao customer – Media – Content news
  • Tao password base package
  • Taobao guest – Tools – Super search

The basic API of Taobao customer includes some other interfaces, and we mainly use this API package.

In this way, we can begin to obtain the promotion information of Taobao customers through THE API interface.

2. Use taobao API in Python environment

After registering as A Taobao customer and adding the promotion position to obtain the basic API of Taobao customer, we can obtain the promotion information of Taobao customer by calling the API of Taobao Customer.

2.1. Understand taobao customer interface

Before calling the API of Taobao.com, let’s take a look at what interfaces are available in the basic API of Taobao.com obtained after submitting the site promotion position:

! [](https://p6-tt-ipv6.byteimg.com/origin/pgc-image/1bbdd9eeb5774715b1c9419c067cb0c9)

There are 23 interfaces in total. Although it is a basic API package, it still contains most of the information in the products promoted by Taobao customers. In this Chat introduction, we mainly use the following two interfaces in the wechat robot created by Taobao customers:

  • Good coupon listing the API guide 【 】 for taobao. TBK. Dg. Item. Coupon. The get
  • Taobao. Tbk.tpwd.create

Other API interfaces can be added to the program according to their own needs.

The good coupon list API is used to return the coupon information of taobao customers’ products. We can search the coupons of products under specific keywords through it and return them to users as results. The parameters it accepts are as follows:

! [](https://p1.pstatp.com/origin/pgc-image/0a500f218275470894a65449bbc3516f)

Taobao customer tao password API, used to convert Taobao customer promotion link to tao password, in order to realize the replication of coupon information, open Taobao can jump to the effect of promotion link. The parameters it accepts are as follows:

! [](https://p1.pstatp.com/origin/pgc-image/8aceba78fee7490587d90ab88406e6f8)

It can be found that we mainly use three parameters: adZoneID, the content of scouring password pop-up and the target link of scouring password jump. Adzoneid can be obtained from the PID of the promotion bit, the content of scouring password pop-up can be set as the title of the product, and the target link of scouring password jump is the link address of coupon. Both parameters are available from the Good coupon Listing API. Let’s look at how to invoke these two interfaces.

2.2. Call taobao Customer API interface

In the introduction of the API interface, we can see that there are multiple language request instances, as follows:

! [](https://p1.pstatp.com/origin/pgc-image/5e7b602598e0465d82c198d1bced6b71)

Best of all, it provides Python request samples, so we can modify the sample code slightly (Python2 in the example) to call taobao’s API, isn’t it nice?

It looks great, but we need to do some extra work.

Download the SDK provided by Ali

See line 2 of the sample code introduces a top. API module, which belongs to the SDK provided by Ali Open Platform, and cannot be downloaded and installed using Python package management tools such as PIP. In each application of Ali development platform, the corresponding SDK download link is provided. We can select “Python version” and click download.

! [](https://p6-tt-ipv6.byteimg.com/origin/pgc-image/1e47a21b5b114d0eb4cdccbf6b8c28c5)

The downloaded SDK is a package called “sdK-python-*****” with a package and an empty folder:

! [](https://p1-tt-ipv6.byteimg.com/origin/pgc-image/66647bfdf31d442e9c06a8f9016c88d9)

The top module we need is in the taobao- sdK-python-auto package. Continue to unpack and obtain the following files:

! [](https://p1.pstatp.com/origin/pgc-image/996f9c9075a3492988142358be58d8c5)

When faced with an unfamiliar package, it’s always a good idea to look at a file like readme to see how to use it. We open the read_me.txt file, which doesn’t contain much, but explains how to use the top module: Copy the top folder to your Python project path so that the Python executor can import the top package.

! [](https://p1.pstatp.com/origin/pgc-image/7416d5c6c61745c28e93557b9b88a756)

After obtaining taobao’s SDK module and how to use the module, we seem to be ready to start. If, like me, you use Python 3, you may have to wait.

This SDK is based on Python 2. If you use it directly in Python 3, you will get an error. The main error is in the base.

! [](https://p1.pstatp.com/origin/pgc-image/717308e0aa084c82a4ce2465dbeaeff8)

We need to convert it to the code style and specification. We can use the 2to3.py tool provided by Python. Here, I have amend the convert well and uploaded to the baidu network location, students in need can be downloaded to replace, links to: pan.baidu.com/s/1PHV2gUVv…

When this is done, our preparations will be over. Let’s use Python to call taobao’s interface.

Call taobao customer API

Currently, our project catalog looks like this:

! [](https://p1.pstatp.com/origin/pgc-image/7eb6575fd628422b95becd68b5810c81)

Under the main folder of the project, there is only one top package of Taobao.com. We create a Python file for debugging the API of calling Taobao.com:

! [](https://p3-tt-ipv6.byteimg.com/origin/pgc-image/d832e32bd2114058aef9be79801f50b5)

First, the package of Taobao customers — top is introduced into usetbkapi.py file, and the public parameters (App Key and App Secret, Both from Ali Open platform – application overview) and good coupon list required adzoneID (Taobao Union – promotion slot management – promotion slot PID MMXXXXXXXXX in the third) :

Import top. API appKey = 'your own appkey' secret =' your own appsecret' adzone_id = adzone_idCopy the code

The first is the good coupon list API, in the API documentation of Ali Open Platform, its request example is as follows:

# -*- coding: utf-8 -*- import top.api req=top.api.TbkDgItemCouponGetRequest(url,port) req.set_app_info(top.appinfo(appkey,secret)) Req. adzone_id=123 req.platform=1 req.cat="16,18" req.page_size=1 req.q=" women "req.page_no=1 try: resp= req.getResponse() print(resp) except Exception,e: print(e)Copy the code

We modify it to the following form:

Def get_tbk_coupon(keyword): req = top.api.TbkDgItemCouponGetRequest() req.set_app_info(top.appinfo(appkey, Secret) req.adzone_id = adzone_id # 1 is the PC terminal, 2 is the wireless terminal, The default is 1 req.platform = 2 # category ID of the item req.cat = "16,18" # number of items returned per page req.page_size = 5 # search term for the item req.q = keyword # number of pages returned for the item req.page_no = 1 try: resp = req.getResponse() print(resp) except Exception as e: print(e)Copy the code

The gettbkCoupon () function accepts a parameter as a search term for taobao merchandise coupons. Let’s run this function with “Python” as the search term and see what is returned:

if __name__ == '__main__':    get_tbk_coupon('python')
Copy the code

The request succeeds and we get a JSON containing five items:

! [](https://p9-tt-ipv6.byteimg.com/origin/pgc-image/e13710f254634e0d8e502c07166d7a05)

After rearranging the JSON, the product information should look like the following:

{'seller_id': 2986712394, 'nick': 'ash官方旗舰店', 'title': 'ASH女装2018春季新款PYTHON系列时尚桑蚕丝流苏系带休闲长裤', 'item_url': 'http://detail.tmall.com/item.htm?id=564660034925', 'num_iid': 564660034925, 'coupon_click_url': 'https://uland.taobao.com/coupon/edetail?e=q48FgUJOzkEGQASttHIRqXXp%2FuJl8%2Bq4zt8H5SH4UobB76UlhXoJ9yIedI0x%2F%2Bc%2BybjT5jgFVwFNRNfT%2FolHl%2B4tM%2BX9QQwt819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikzNXyo71Icu6djhR%2BLpQ%3D&traceId=0bba60d215239195072098617e', 'coupon_remain_count': 7910, 'category': 16, 'commission_rate': '10.00', 'shop_title': 'ash官方旗舰店', 'coupon_info': '满1400元减200元', 'user_type': 1, 'pict_url': 'http://img.alicdn.com/tfscom/i2/2986712394/TB13ygTlL9TBuNjy0FcXXbeiFXa_!!0-item_pic.jpg', 'item_description': '桑蚕丝', 'coupon_end_time': '2018-04-20', 'coupon_start_time': '2018-04-16', 'small_images': {'string': ['http://img.alicdn.com/tfscom/i4/2986712394/TB21pubaOOYBuNjSsD4XXbSkFXa_!!2986712394.jpg']}, 'coupon_total_count': 10000, 'zk_final_price': '2297.00', 'volume': 0}
{'seller_id': 3126607078, 'nick': '尚斯美丽旗舰店', 'title': '人生苦短我用PYTHON  程序员源代码极客geek语言短袖T恤上衣衣服', 'item_url': 'http://detail.tmall.com/item.htm?id=557116340483', 'num_iid': 557116340483, 'coupon_click_url': 'https://uland.taobao.com/coupon/edetail?e=uvBu32XC6ScGQASttHIRqZS0LX9LKeP4%2F%2BhNcy%2FKOAPl43M3mIB1t9VU8DHamaG1OypG%2BG0aTLQ0F0zg%2Fses2Svsgj6gOf8L819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikzNXyo71Icu6djhR%2BLpQ%3D&traceId=0bba60d215239195072098617e', 'coupon_remain_count': 9711, 'category': 16, 'commission_rate': '5.50', 'shop_title': '尚斯美丽旗舰店', 'coupon_info': '满5元减3元', 'user_type': 1, 'pict_url': 'http://img.alicdn.com/tfscom/i3/3126607078/TB1BqiMSVXXXXbXXXXXXXXXXXXX_!!0-item_pic.jpg', 'item_description': '', 'coupon_end_time': '2018-09-30', 'coupon_start_time': '2018-04-03', 'small_images': {'string': ['http://img.alicdn.com/tfscom/i2/3126607078/TB243pGacqGJuJjSZFyXXXFvpXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i1/3126607078/TB22q64XzjmJKJjy0FjXXcLnFXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i3/3126607078/TB2jLKxXMOFJuJjSspaXXb.mXXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i1/3126607078/TB2Yv4CaiaGJuJjSZFOXXbWjVXa_!!3126607078.jpg']}, 'coupon_total_count': 10000, 'zk_final_price': '59.00', 'volume': 13}
{'seller_id': 3126607078, 'nick': '尚斯美丽旗舰店', 'title': '人生苦短PYTHON当歌 短袖T恤衫 程序员源代码极客geek语言', 'item_url': 'http://detail.tmall.com/item.htm?id=557251066538', 'num_iid': 557251066538, 'coupon_click_url': 'https://uland.taobao.com/coupon/edetail?e=ntKy08HcshwGQASttHIRqX7JS835xJ9MYpAE%2F40qTYHl43M3mIB1t9VU8DHamaG1OypG%2BG0aTLQ0F0zg%2Fses2Svsgj6gOf8L819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikzNXyo71Icu6djhR%2BLpQ%3D&traceId=0bba60d215239195072098617e', 'coupon_remain_count': 9711, 'category': 16, 'commission_rate': '5.50', 'shop_title': '尚斯美丽旗舰店', 'coupon_info': '满5元减3元', 'user_type': 1, 'pict_url': 'http://img.alicdn.com/tfscom/i2/3126607078/TB1.myFQpXXXXbdXVXXXXXXXXXX_!!0-item_pic.jpg', 'item_description': '', 'coupon_end_time': '2018-09-30', 'coupon_start_time': '2018-04-03', 'small_images': {'string': ['http://img.alicdn.com/tfscom/i1/3126607078/TB2oQWuXMSFJuJjSszdXXbVgXXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i1/3126607078/TB21PH6XA2kJKJjSspcXXbS1pXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i2/3126607078/TB23zY1XyHmJKJjy0FfXXb9aVXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i4/3126607078/TB2vEqvXROBJuJjy1XdXXXIXVXa_!!3126607078.jpg']}, 'coupon_total_count': 10000, 'zk_final_price': '59.00', 'volume': 0}
{'seller_id': 3126607078, 'nick': '尚斯美丽旗舰店', 'title': '人生苦短我用python程序员印花男女圆领geek纯棉短袖T恤上衣衣服', 'item_url': 'http://detail.tmall.com/item.htm?id=558077802593', 'num_iid': 558077802593, 'coupon_click_url': 'https://uland.taobao.com/coupon/edetail?e=juGQGSsPBJ0GQASttHIRqT2olWwoa5nHNSJRwfE7%2FEbl43M3mIB1t9VU8DHamaG1OypG%2BG0aTLQ0F0zg%2Fses2Svsgj6gOf8L819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikzNXyo71Icu6djhR%2BLpQ%3D&traceId=0bba60d215239195072098617e', 'coupon_remain_count': 9711, 'category': 16, 'commission_rate': '5.50', 'shop_title': '尚斯美丽旗舰店', 'coupon_info': '满5元减3元', 'user_type': 1, 'pict_url': 'http://img.alicdn.com/tfscom/i2/3126607078/TB1uhsvcOAKL1JjSZFoXXagCFXa_!!0-item_pic.jpg', 'item_description': '', 'coupon_end_time': '2018-09-30', 'coupon_start_time': '2018-04-03', 'small_images': {'string': ['http://img.alicdn.com/tfscom/i3/3126607078/TB2HowocKEJL1JjSZFGXXa6OXXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i3/3126607078/TB28oMocKEJL1JjSZFGXXa6OXXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i2/3126607078/TB2vgYOciFTMKJjSZFAXXckJpXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i4/3126607078/TB232EscOwIL1JjSZFsXXcXFFXa_!!3126607078.jpg']}, 'coupon_total_count': 10000, 'zk_final_price': '58.00', 'volume': 2}
{'seller_id': 3126607078, 'nick': '尚斯美丽旗舰店', 'title': '人生苦短PYTHON当歌 程序员源代码极客geek语言卫衣', 'item_url': 'http://detail.tmall.com/item.htm?id=557367483076', 'num_iid': 557367483076, 'coupon_click_url': 'https://uland.taobao.com/coupon/edetail?e=Al70aB%2Bs3ogGQASttHIRqV3ogvGhwDOLULyxS8nhatHl43M3mIB1t9VU8DHamaG1OypG%2BG0aTLQ0F0zg%2Fses2Svsgj6gOf8L819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikzNXyo71Icu6djhR%2BLpQ%3D&traceId=0bba60d215239195072098617e', 'coupon_remain_count': 9711, 'category': 16, 'commission_rate': '5.50', 'shop_title': '尚斯美丽旗舰店', 'coupon_info': '满5元减3元', 'user_type': 1, 'pict_url': 'http://img.alicdn.com/tfscom/i4/3126607078/TB1eY9vSVXXXXcoaXXXXXXXXXXX_!!0-item_pic.jpg', 'item_description': '', 'coupon_end_time': '2018-09-30', 'coupon_start_time': '2018-04-03', 'small_images': {'string': ['http://img.alicdn.com/tfscom/i2/3126607078/TB2GoPNXPTlJKJjSszbXXXS1FXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i1/3126607078/TB2k0IgaCGFJuJjSZFuXXcAyFXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i3/3126607078/TB2vUvNXPvmJKJjy0FlXXXGdFXa_!!3126607078.jpg', 'http://img.alicdn.com/tfscom/i3/3126607078/TB24VnQXPLlJKJjSsppXXXqgFXa_!!3126607078.jpg']}, 'coupon_total_count': 10000, 'zk_final_price': '88.00', 'volume': 0}
Copy the code

Because our query is the default apparel goods now, so back to the five commodity title contains “Python” clothing is responsible for the goods, we pay attention to the field of commodity information, good coupon listing the API documentation for: open.taobao.com/docs/api.ht…

'seller_id': seller ID 'Nick ': seller nickname 'title': item title' item_URL ': item link' num_iID ': item ID 'coupon_click_URL ': 'Coupon_remain_count ': number of coupons left' Category ': Category of goods 'commission_rate': commission rate' shop_title': shop name 'coupon_info': Coupon info 'user_type': 1, seller type' pict_URL ': link to the main picture of the product 'item_description': product description' coupon_end_time': coupon end time' coupon_start_time': 'SMALL_images ': a small list of items 'coupon_total_count': number of coupons' Zk_final_price ': discounted price (i.e. at sale price) 'volume': 30 days of salesCopy the code

From the information returned, we can make a simple product information, not table here. Let’s look at the product coupon link field CouponClickURL. This field returns a coupon COUPON URL link. We click on one of the results:

'coupon_click_url': 'https://uland.taobao.com/coupon/edetail?e=Al70aB%2Bs3ogGQASttHIRqV3ogvGhwDOLULyxS8nhatHl43M3mIB1t9VU8DHamaG1OypG%2BG0aT LQ0F0zg%2Fses2Svsgj6gOf8L819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikzNXyo71 Icu6djhR%2BLpQ%3D&traceId=0bba60d215239195072098617e'Copy the code

Click to open it on the computer, and it will display the common coupon page in Taobao software:

! [](https://p1.pstatp.com/origin/pgc-image/fcaffa30843249c4a43307cf21617750)

Let’s move on to the password scouring API.

Tao password is a way to promote Taobao, specifically for the wireless end of the commodity promotion. Tao password copied on the phone, open taobao software, will automatically jump to tao password target link. So tao password is equivalent to a code taobao software, not only to avoid other platforms to taobao customer links blocked, but also convenient to promote and spread. General taobao Union automatically generated tao password promotion information as follows:

! [](https://p1.pstatp.com/origin/pgc-image/a83bd1a46a344f329f4e16257809623e)

We now use tao password API to generate tao password of Taobao customer commodity coupons.

New password API documentation links for: open.taobao.com/docs/api.ht…

The request parameters accept two mandatory parameters and three optional parameters. The parameter information is as follows:

! [](https://p1.pstatp.com/origin/pgc-image/8d99e570d31b4ca6850a12f1b88345c6)

Here, we use the title of the product as the value of parameter text, the coupon link of the product as the value of parameter URL, and my own head as the logo of the pop-up box of Tao Password as an optional parameter.

If the request succeeds, it will return json of the following form:

{" tbk_tpwd_create_response ": {" data" : {" model ":" RMB AADPOKFz RMB "}}}Copy the code

The model value is the generated tao password.

An example request for the password scouring API is:

# -*- coding: utf-8 -*- import top.api req=top.api.TbkTpwdCreateRequest(url,port) req.set_app_info(top.appinfo(appkey,secret)) The req. User_id = "123" the req. Text = "length is greater than five characters" is the req. Url = "https://uland.taobao.com/" is the req. Logo = "https://uland.taobao.com/" req.ext="{}" try: resp= req.getResponse() print(resp) except Exception,e: print(e)Copy the code

We also modified it to make it easier to pass parameters and call. The modified password request looks like this:

Def generate_ttoken(url,text): req = top.api.TbkTpwdCreateRequest() req.set_app_info(top.appinfo(appkey, secret)) req.text = text req.url = url req.logo = "http://ozuz7s0lj.bkt.clouddn.com/avas.webp" try: resp = req.getResponse() print(resp) except Exception as e: print(e)Copy the code

Call generate_ttoken() in the gettBkCoupon () function that gets the commodity coupon. The complete code is as follows:

# -*- coding: Utf-8 -* -import top. API appKey = 'your own appkey' secret =' your own secret' adzone_id = your own adzone_id # get taobao guest merchandise coupon def get_tbk_coupon(keyword): req = top.api.TbkDgItemCouponGetRequest() req.set_app_info(top.appinfo(appkey, Secret) req.adzone_id = adzone_id # 1 is the PC terminal, 2 is the wireless terminal, The default is 1 req.platform = 2 # category ID of the item req.cat = "16,18" # number of items returned per page req.page_size =5 # search term for the item req.q = keyword # number of pages returned for the item req.page_no = 1 try: resp = req.getResponse() for r in resp['tbk_dg_item_coupon_get_response']['results']['tbk_coupon']: Coupon_url = r[' coupon_click_URL '] coupon_text = r['title'] print(">>> ",coupon_url) generate_ttoken(coupon_url,coupon_text) print() except Exception as e: Def generate_ttoken(url,text): req = top.api.TbkTpwdCreateRequest() req.set_app_info(top.appinfo(appkey, secret)) req.text = text req.url = url req.logo = "http://ozuz7s0lj.bkt.clouddn.com/avas.webp" try: resp = req.getResponse() print(resp['tbk_tpwd_create_response']['data']['model']) except Exception as e: print(e) if __name__ == '__main__': get_tbk_coupon('python')Copy the code

Finally get the commodity title of each commodity, commodity coupon link and commodity coupon tao password:

>>> Product Title: ASH Women's Spring 2018 New PYTHON Collection Fashion Silkworm Fringed Lace Casual Pants >>> Coupon Link:  https://uland.taobao.com/coupon/edetail?e=8PzLtaUTd6gGQASttHIRqXXp%2FuJl8%2Bq4zt8H5SH4UobB76UlhXoJ9yIedI0x%2F%2Bc%2Bybj T5jgFVwFNRNfT%2FolHl%2B4tM%2BX9QQwt819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5w HikzNXyo71IiVRoyFb % 2 BVTQ % 3 d & traceId = 0 ab2019315239230452104699e RMB mFES0INe2ZG RMB > > > goods title: Life is short I use PYTHON programmer source code geek Geek language Short sleeve T-shirt top clothes >>> Coupon link:  https://uland.taobao.com/coupon/edetail?e=%2BC2j8zvxzA8GQASttHIRqZS0LX9LKeP4%2F%2BhNcy%2FKOAPl43M3mIB1t9VU8DHamaG1OypG% 2BG0aTLQ0F0zg%2Fses2Svsgj6gOf8L819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikz NXyo71IiVRoyFb % 2 BVTQ % 3 d & traceId = 0 ab2019315239230452104699e RMB ZMnD0INeagd RMB > > > goods title: Life is short PYTHON when song Short-sleeved T-shirt programmer source code geek Geek language >>> Coupon link:  https://uland.taobao.com/coupon/edetail?e=OPzNwziJE54GQASttHIRqX7JS835xJ9MYpAE%2F40qTYHl43M3mIB1t9VU8DHamaG1OypG%2BG0aT LQ0F0zg%2Fses2Svsgj6gOf8L819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikzNXyo71 IiVRoyFb % 2 BVTQ % 3 d & traceId = 0 ab2019315239230452104699e $9 qbz0in3w6s RMB > > > goods title: Life is short I use Python programmer printed men's and women's Geek cotton Short sleeve T-shirt top clothes >>> Coupon link:  https://uland.taobao.com/coupon/edetail?e=oiGwbaF8KwgGQASttHIRqT2olWwoa5nHNSJRwfE7%2FEbl43M3mIB1t9VU8DHamaG1OypG%2BG0aT LQ0F0zg%2Fses2Svsgj6gOf8L819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikzNXyo71 IiVRoyFb % 2 BVTQ % 3 d & traceId = 0 ab2019315239230452104699e RMB hQ1d0IN3Dck RMB > > > goods title: life is too short PYTHON source code geek when song programmer language geek who dress > > > coupon link:  https://uland.taobao.com/coupon/edetail?e=0ELzl1VPgRgGQASttHIRqV3ogvGhwDOLULyxS8nhatHl43M3mIB1t9VU8DHamaG1OypG%2BG0aTLQ 0F0zg%2Fses2Svsgj6gOf8L819cieM8MLbxkVtSX4VxL71PCn8gJl5TQqhWEgLxGimRzzicfAm7p1hAmztsbMhPVcPqzC25aNxIH07HK3v5wHikzNXyo71Ii VRoyFb % 2 BVTQ % 3 d & traceId = 0 ab2019315239230452104699e RMB osZw0IN3Emh RMBCopy the code

In the returned results, each starting and ending with RMB symbol is tao password, we send it to the mobile phone, and then copy tao password through the mobile phone, to see the effect of tao password:

Send one of the texts to wechat’s file Transfer assistant:

! [](https://p6-tt-ipv6.byteimg.com/origin/pgc-image/cb7280c6d98543a08a9f21e8610a47d3)

Copy this information and open Taobao to find a friend’s password sharing:

! [](https://p26-tt.byteimg.com/origin/pgc-image/c87619b8446c4184b8870e6e4887291f)

Click open, there will appear the page of commodity coupon:

! [](https://p6-tt-ipv6.byteimg.com/origin/pgc-image/757cb1cc8e244ee5a11da79e9ae96b36)

In this way, we successfully called Taobao customer API through Python, and realized the function of obtaining taobao customer commodity coupons and converting the password of coupon scouring.

Now that we have finished using taobao’s API, let’s learn how to create a smiling robot.

Because space is limited, so in the next article we will create a robot!

PS: If you need Python learning materials, please click on the link below to obtain them

For the full code or tutorial, click here