Quantcast
Channel: 《》的评论
Viewing all articles
Browse latest Browse all 63

Python 实现微信小程序”抽奖助手”的自动抽奖功能

$
0
0

最近因为隔离在家,在B站自学了 Python、Javascript、Git、Linux 等各种课程,因为之前学过C、汇编、PHP的经验,基本上都是2倍速过的,很容易。发现 Python 真的很简单。而且模块也很多。最近在玩爬虫,看到小甲鱼又开始抽奖了,于是就有了这个用 Python 实现每日自动抽奖的教程。

本来觉得这个功能肯定有人做了,想直接把代码 Copy 下来,然后直接使用,没想到,网上只找到两个人的代码,而且,都报错,不过好在提供了思路。

思路

1. 用 Fiddler 抓包
虽然可以配置证书、代理用手机抓包,不过这样挺麻烦的,在B站看过有人说可以用桌面版微信,然后将小程序转发给自己,然后在电脑上进行抓包。试了一下,果然挺好用的。在 Fiddler 里边最重要的起始就是两个包,如图所示:

2. 数据分析
根据 Fiddler 抓包结果来看,可以看出来,一个包是获取抽奖列表的,另一个包是我们点击参与抽奖的。而参与抽奖里边需要 POST 一个 URL,那么中间有一段随机乱码,这个乱码应该就是抽奖商品的ID了,那么这个ID从哪来呢?

回到第一个包,在回返数据中,我们可以看到 Public 和 Square 两个数据,就是对应着公共抽奖,和自助抽奖。里边的ID正好对应着我们之前的URL里边的ID。

代码

记得需要安装并引入 requests 模块

import requests


def main():
    url = "https://lucky.nocode.com/v2/lottery/public"
    headers = {
        # 请修改为自己的 Authorization
        "Authorization": "你自己的 Authorization"}
    res = requests.get(url, headers=headers)
    public_info = res.json()['public']
    square_info = res.json()['square']
    for p_id in public_info:
        p_url = 'https://lucky.nocode.com/v2/lottery/%s/join' % p_id['id']
        res = requests.post(p_url, headers=headers)
        data = res.json()
        if res.status_code == 200 and 'errors' not in data:
            print("成功参与抽奖:《%s》" % (p_id['prizes']['data'][0]['name']))
        else:
            print("Whoops, Something Happened")
    for s_id in square_info:
        p_url = 'https://lucky.nocode.com/v2/lottery/%s/join' % s_id['id']
        res = requests.post(p_url, headers=headers)
        data = res.json()
        if res.status_code == 200 and 'errors' not in data:
            print("成功参与抽奖:《%s》" % (s_id['prizes']['data'][0]['name']))
        else:
            print("Whoops, Something Happened")


if __name__ == '__main__':
    main()

测试了一下,成功!

成功参与抽奖:《玛可安迪口红香水套盒 倾心爱恋甜美礼盒》
成功参与抽奖:《JOINFIT 暴汗腰带》
成功参与抽奖:《Pinlo 榨汁机》
成功参与抽奖:《医学大神 14 册套装》
成功参与抽奖:《B.DUCK 临时停车号码牌》
成功参与抽奖:《dw 手镯》
成功参与抽奖:《卡西欧BABY-G樱花粉》
成功参与抽奖:《迪奥 888 发财色💄 》
成功参与抽奖:《匡威 1970 颜色任你选》
成功参与抽奖:《纪梵希新款 N37》
成功参与抽奖:《王一博同款守护之眼项链》
成功参与抽奖:《免费送阿玛尼电光蓝色大师气垫一盒》
成功参与抽奖:《DW 手镯一个》

代码已经上传到我的 Github:
https://github.com/Forece/wechat_lottories

ref:
https://blog.csdn.net/zhusongziye/article/details/79887234
https://cloud.tencent.com/developer/article/1165239


Viewing all articles
Browse latest Browse all 63

Trending Articles


Mga Patama sa mga Nagmamahal the Best Tagalog love quotes for you


Vimeo 10.7.1 by Vimeo.com, Inc.


Sapos para colorear


tagalog love Quotes – Tiwala Quotes


“Tado” Jimenez Quotes Collections Online


5 Tagalog Relationship Rules


Hugot Lines 2020 Patama : ML Edition


Re:Mutton Pies (lleechef)


Vimeo 10.7.0 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE


Girasoles para colorear


Pokemon para colorear


Presence Quotes – Positive Quotes


Maganda Quotes – tagalog Quotes – Inggit Quotes


EASY COME, EASY GO


Top 10 Best Tagalog Friendship Quotes and Sayings | mrbolero


“BAHAY KUBO HUGOT”


RE: Mutton Pies (frankie241)


Long Distance Relationship Tagalog Love Quotes


HOY PANGIT, MAGBAYAD KA!