获取淘宝优惠券

1 前言

经常看到别人在淘宝买东西可以领到好多优惠券,我也想要啊,于是利用自己毕生所学,通过各种百度,搜刮全网各种信息,终于找到一个可以查找优惠券的接口,梦想得以实现了,哈哈哈哈。。。实在是太开心了,今天分享给大家。

2 获取淘宝优惠券

2.1 获取淘宝口令文字

  • 在淘宝找到想要购买的物品,点击分享,然后点击复制链接即可复制该物品的口令

  • 找一个空白文件进行粘贴,即可获得该物品的淘宝口令文字

幅治本段内容₤51Pn1CY8Djc₤咑幵淘tao寳【爱国者正品新款红轴个性创意机械键盘炫彩背光电竞吃鸡LOL游戏装备有线键盘台式笔记本电脑男女办公通用USB】

注:其中₤51Pn1CY8Djc₤即淘宝口令

2.2 提取淘宝口令

使用正则匹配提取淘宝口令。

代码如下:

import re # 判断是否含有淘宝口令 def judge_code(words): pat = re.compile("[₳$¢₴€₤¥$《(₰]" + r"\w{11}" + "[₳$¢₴€₤¥$《)₰]") result = pat.findall(words) if result: return result[0] return False if __name__ == '__main__': words = "幅治本段内容₤51Pn1CY8Djc₤咑幵淘tao寳【爱国者正品新款红轴个性创意机械键盘炫彩背光电竞吃鸡LOL游戏装备有线键盘台式笔记本电脑男女办公通用USB】" kl = judge_code(words) if kl: print("淘宝口令为:", kl) else: print("该段文字中不包含淘宝口令")

运行结果如下:

2.3 获取该物品的id

准备工作:

代码如下:

import json import requests def get_info(old_code): params = { "param.sort": "0", "param.page": "1", "param.pageSize": "100", "param.keyWord": old_code } # 发送请求 resp = requests.get(info_url, params=params, headers=headers) # 判断是否正确返回 if resp.status_code != 200: return False else: content = resp.text id = json.loads(content)["PData"][0]["num_iid"] return id if __name__ == '__main__': # 获取物品id的URL info_url = "http://mgi.sitezt.cn/api/i/cmsitem/cmsqwsearch" # 请求头 headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Cache-Control": "no-cache", "Connection": "keep-alive", "Host": "mgi.sitezt.cn", "Pragma": "no-cache", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" } old_code = "₤51Pn1CY8Djc₤" id = get_info(old_code) if id: print("该物品淘宝id为:", id) else: print("获取该物品淘宝id失败!")

运行结果如下:

2.4 获取含有优惠券的淘宝口令

准备工作:

代码如下:

import json import requests def get_code(id): params = { "Dto.rId": "2318806650", "Dto.inviteCode": "ZC4V7HY", "Dto.shortInviteCode": "", "Dto.pId": "", "Dto.userToken": "", "Dto.domain": "7gv.7fw48.cn", "Dto.itemId": id, "Dto.needInviteCode": "true", "Dto.againLess": "true", "Dto.newUserInfo": "true", "Dto.itemInfo": "true", "Dto.url": "true", "Dto.kL": "true", "Dto.shortUrl": "true", "Dto.downloadGuide": "true" } resp = requests.get(code_url, params=params, headers=headers) # 判断是否正确返回 if resp.status_code != 200: return False else: content = resp.text new_kl = json.loads(content)["KL"] return new_kl if __name__ == '__main__': # 获取优惠券淘宝口令网站 code_url = "http://mgi.sitezt.cn/api/b/buy" # 请求头 headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Cache-Control": "no-cache", "Connection": "keep-alive", "Host": "mgi.sitezt.cn", "Pragma": "no-cache", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" } id = "579587549572" new_kl = get_code(id) if new_kl: print("该物品优惠券淘宝口令为:", new_kl) else: print("获取该物品优惠券淘宝口令失败!")

运行结果如下:

3 代码汇总

import json import re import requests class YouHuiQuan(): def __init__(self): # 获取物品信息的URL self.info_url = "http://mgi.sitezt.cn/api/i/cmsitem/cmsqwsearch" # 获取物品优惠券的URL self.code_url = "http://mgi.sitezt.cn/api/b/buy" # 请求头 self.headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Cache-Control": "no-cache", "Connection": "keep-alive", "Host": "mgi.sitezt.cn", "Pragma": "no-cache", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" } def get_info(self, old_code): params = { "param.sort": "0", "param.page": "1", "param.pageSize": "100", "param.keyWord": old_code } # 发送请求 resp = requests.get(self.info_url, params=params, headers=self.headers) # 判断是否正确返回 if resp.status_code != 200: return False else: content = resp.text id = json.loads(content)["PData"][0]["num_iid"] return id def get_code(self, id): params = { "Dto.rId": "2318806650", "Dto.inviteCode": "ZC4V7HY", "Dto.shortInviteCode": "", "Dto.pId": "", "Dto.userToken": "", "Dto.domain": "7gv.7fw48.cn", "Dto.itemId": id, "Dto.needInviteCode": "true", "Dto.againLess": "true", "Dto.newUserInfo": "true", "Dto.itemInfo": "true", "Dto.url": "true", "Dto.kL": "true", "Dto.shortUrl": "true", "Dto.downloadGuide": "true" } resp = requests.get(self.code_url, params=params, headers=self.headers) # 判断是否正确返回 if resp.status_code != 200: return False else: content = resp.text KL = json.loads(content)["KL"] return KL # 判断是否含有淘宝口令 def judge_code(self, words): pat = re.compile("[₳$¢₴€₤¥$《(₰]" + r"\w{11}" + "[₳$¢₴€₤¥$《)₰]") result = pat.findall(words) if result: return result[0] return False if __name__ == '__main__': # words = "幅治本段内容₤51Pn1CY8Djc₤咑幵淘tao寳【爱国者正品新款红轴个性创意机械键盘炫彩背光电竞吃鸡LOL游戏装备有线键盘台式笔记本电脑男女办公通用USB】" yhq = YouHuiQuan() words = input("请输入淘宝链接:") kl = yhq.judge_code(words) if kl: print("淘宝口令为:", kl) else: print("该段文字中不包含淘宝口令") id = yhq.get_info(kl) if id: print("该物品淘宝id为:", id) else: print("获取该物品淘宝id失败!") new_kl = yhq.get_code(id) if new_kl: print("该物品优惠券淘宝口令为:", new_kl) else: print("获取该物品优惠券淘宝口令失败!")

运行结果:

请输入淘宝链接:幅治本段内容₤51Pn1CY8Djc₤咑幵淘tao寳【爱国者正品新款红轴个性创意机械键盘炫彩背光电竞吃鸡LOL游戏装备有线键盘台式笔记本电脑男女办公通用USB】
淘宝口令为: ₤51Pn1CY8Djc₤
该物品淘宝id为: 579587549572
该物品优惠券淘宝口令为: ₰wl5q1C15Ofx₰

4 检验效果

复制该口令(₰i4fb1CYEdHv₰),并打开淘宝,如下图所示:

  • 点击打开

  • 点击立即领券

  • 然后进行下单,如图所示:店铺优惠,减200大洋

大功告成,可以快快乐乐的剁手了,再也不用担心买贵了,哈哈哈~

什么???不会写代码???嫌麻烦???好吧!!!

下面二维码帮你搜优惠券

效果如下:

原文链接:https://blog.csdn.net/apollo_miracle/article/details/107183820?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165277499316782388046619%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165277499316782388046619&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-21-107183820-null-null.nonecase&utm_term=%E4%BC%98%E6%83%A0

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
文明发言,共建和谐米科社区
提交
头像

昵称

取消
昵称表情图片