依据淘客API检索优惠劵
淘客大伙儿应当不生疏,专业发各种各样内部优惠券的服务平台,派发的人能够获得提成,今日说而言下应用python读取淘客api检索优惠劵的正确姿势
安裝topsdk
topsdk 是淘客python插口sdk,集成化较为全方位,还可以在阿里联盟自主免费下载官方网的sdk(有的处理沒有出示,必须自己来写)
(venv) $ pip install topsdk
获得优惠劵的插口
top.api.TbkDgMaterialOptionalRequest()
完成编码
import top
import re
import requests
import json
appkey = '123'
secret = 'asdfasfweasf'
adzone_id = '234345345435'
# 获得淘口令
def get_token(url, text):
req = top.api.TbkTpwdCreateRequest()
req.set_app_info(top.appinfo(appkey, secret))
req.text = text
req.url = url
try:
resp = req.getResponse()['tbk_tpwd_create_response']['data']['model']
return resp
except Exception as e:
print(e)
return None
# 根据淘客API检索优惠劵
def get_tk_coupon(kw,size=5):
req = top.api.TbkDgMaterialOptionalRequest()
req.set_app_info(top.appinfo(appkey, secret))
req.adzone_id = int(adzone_id)
req.platform = 2
req.page_size = size
req.q = kw
req.page_no = 1
try:
# print('===',req.getResponse())
resp = req.getResponse()['tbk_dg_material_optional_response']['result_list']['map_data']
return resp
except Exception as e:
print(e)
return None
if __name__ == "__main__":
response = get_tk_coupon('金稻直发梳直发夹板长直发卷头发双用武器卷发夹不损发空气负离子懶人女迷中小型')
# print(resp)
for r in response:
# 商品标题
ordername = r['title']
# 产品当今价
orderprice = r['zk_final_price']
coupon_info = r['coupon_info']
coupon_demonination = int(re.findall(r'(\d )', coupon_info)[-1])
# 商品信息
orderimg = r['pict_url']
# 获得淘口令
token = get_token(url='https:' r['url'], text=r['title'])
# 券后价
couponprice = round(float(orderprice) - int(coupon_demonination), 1)
link = r['item_url']
msgs = '''/:gift{name}\n/:rose【在市场价】{orderprice}元\n/:heart【券后价】{conponprice}元\n/:cake 【限时抢购连接】{link_short}\n-----------------\n拷贝这条信息内容\n{token}开启【手机版淘宝】,就可以查询\n------------------\n
'''.format(name=ordername, orderprice=orderprice, conponprice=couponprice, token=token,
link_short=link)
print(msgs)