先看实现图:
爬虫笔记24——纷玩岛(某岛)自动抢票脚本笔记-LMLPHP

以下内容仅供交流学习使用!!!
获取Authorization是最关键的,X岛目前的接口请求比较简单

一、获取Authorization凭证

这个是用户的认证凭据,是小程序可以确保只有经过授权的用户才能访问敏感资源或执行特定操作。这有助于防止未经授权的访问和操作,从而保护资源的安全性,在后续所有的接口请求中都需要携带这个Authorization参数。类似于就是token令牌,唯一标识符。
爬虫笔记24——纷玩岛(某岛)自动抢票脚本笔记-LMLPHP

二、几个关键的参数

# 开抢时间
START_TIME = "2024-11-27 15:00:00"
# 演唱会的ID,需要获取对应演唱会的id
PROJECT_ID = '3913913419'
# 要抢的 票价,记得输入有的票价,不然无法筛选对应的座位id
PRICE = 320
# 收件人信息
NAME = '收件人'
# 手机号码
PHONE = '17777777777'
# 观演人数量
COUNT = 2

三、几个关键的接口

获取参数v,这个参数其实可以写死,可忽略

# 获取参数v
    def cdn_token(self):
        headers = {
            'authority': 'livelabassets.livelab.com.cn',
            'accept': '*/*',
            'accept-language': 'zh-CN,zh;q=0.9',
            'content-type': 'application/json',
            'referer': 'https://servicewechat.com/wx5a8f481d967649eb/101/page-frame.html',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'cross-site',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090a13) XWEB/8555',
            'xweb_xhr': '1',
        }

        params = {
            't': str(int(time.time() * 1000)),
        }

        response = requests.get('https://livelabassets.livelab.com.cn/app/homepage/cdnToken.json', params=params,
                                headers=headers)
        # print(response.status_code)
        # 这里会返回一个v参数,但经过验证就是写死不变的,其实这个接口不用请求直接写死也可以
        # print(response.json()['data']['v'])
        self.v = response.json()['data']['v']

通过价位获取演出的参数信息

 # 通过价位获取想要价位的座位id
    def ticket_info(self):
        seat_list = list()
        for seat in self.perform_info['seatPlans']:
            seat_list.append(str(seat['seatPlanId']))
        seatPlanIds = ','.join(seat_list)
        response = requests.get(
            f'https://api.livelab.com.cn/performance/app/ticket/ticketInfo?seatPlanIds={seatPlanIds}&projectId={PROJECT_ID}&v={self.v}',
            headers=self.headers,
        )
        # print(response.status_code)
        for temp in response.json()['data']['ordinaryTicketVos']:
            if temp['seatPlanPrice'] == PRICE:
                return temp

获取观演人信息,账号提前录入即可

# 获取观演人信息
    def get_audience_list(self):
        response = requests.get('https://api.livelab.com.cn/member/member/bearer/app/list', headers=self.headers)
        print(response.status_code)
        return response.json()['data']

提交订单接口

    # 生成订单接口
    def create_orders(self):
        ticket_info = self.ticket_info()
        audiences = self.get_audience_list()
        frequent_ids = []
        for i in range(COUNT):
            frequent_ids.append(audiences[i]['frequentContactsId'])
        print(ticket_info)
        json_data = {
            'deliveryType': 1,
            'contactName': NAME,
            'contactPhone': PHONE,
            'combineTicketVos': None,
            'ordinaryTicketVos': None,
            'payment': ticket_info['seatPlanPrice'],
            'totalPrice': ticket_info['seatPlanPrice'] * COUNT,
            'performId': self.perform_info['id'],
            'projectId': PROJECT_ID,
            'privilegeCodeList': [],
            'audienceCount': COUNT,
            'frequentIds': frequent_ids,
            'seatPlanIds': [
                ticket_info['seatPlanId'],
            ],
            'blackBox': ':0',
        }

        response = requests.post('https://api.livelab.com.cn/order/app/center/v3/create', headers=self.headers, json=json_data)
        if response.status_code == 200:
            print(response.status_code)
            print(response.text)
            return response.json()["msg"]

以上就是X岛实现抢票的关键几个接口!冲!
可添加我V沟通(注明来意):可购买学习资料提升自己,靠别人不如靠自己,不难的

11-28 21:57