【求助】急,嘎嘎急抽奖那个代码,头疼 403

今天白天比较忙,测试抽奖代码测试一半,有事情就放一边了

现在是根据那个佬友给的方案,我目前得到都是403。

import requests
import random


def get_candidate_list(topic_id):
    headers = {
        'Cookie': ""
        # 打开https://linux.do/t/topic/166273.json页面,注意修改topic_id,获取这个页面的 cookie 填入
    }
    candidate_list = []
    name_list = set()
    url = 'https://linux.do/t/topic/{}.json?page={}'
    for i in range(1, 1000):
        resp = requests.get(url.format(topic_id, i), headers=headers, timeout=10)
        print("查询第{}页".format(i), resp.status_code, 'code')
        if resp.status_code == 404:
            print("已经到达最后一页")
            break
        if resp.status_code == 403:
            print("【带锁的帖子】没有权限查看请求的资源。我也不会了")
            exit()
            return None
        result = resp.json()
        posts = result["post_stream"]["posts"]
        topic_owner = posts[0]["username"]
        for i in posts:
            only_name = i["username"]
            if (only_name not in name_list) and (only_name != topic_owner):  # 去除楼主和重复username
                candidate = {
                    "only_name": only_name,
                    "display_name": i["display_username"],
                    "post_text": i["cooked"],
                    "post_number": i["post_number"]
                }
                candidate_list.append(candidate)
            name_list.add(i["username"])
    return candidate_list


def start(topic_id, winner_number):
    candidates = get_candidate_list(topic_id)
    url = "https://linux.do/t/topic/" + topic_id
    if len(candidates) < winner_number:
        print(f'\n主题共 {len(candidates)} 个有效回复参与抽奖(不包含楼主和重复回帖),少于中奖者人数【{winner_number}】,'
              f'所有用户中奖\n【{len(candidates)}】位中奖者信息如下:\n')
        for x in candidates:
            print_user_info(x, url)
        return
    print(f"\n主题共 {len(candidates)} 个有效回复参与抽奖(不包含楼主和重复回帖):\n【{winner_number}】位中奖者信息如下:\n")
    for x in (random.sample(candidates, winner_number)):
        print(x, url)

    print("\n复制以上内容发帖即可。")


def print_user_info(user, url):
    winner_id = user["only_name"]
    winner_name = user["display_name"]
    winner_text = user["post_text"]
    winner_floor = user["post_number"]
    print(f"# 恭喜 {winner_name}(@{winner_id}),楼层 [{winner_floor}]({url}/{winner_floor})  \n回帖内容:\n> {winner_text}\n")


if __name__ == "__main__":
    topic_id = '166273'  # topic_id
    winner_number = 300  # 中奖人数
    start(topic_id, winner_number)

明天就要抽奖了,白天有事情只能熬夜搞一下,结果……

急啊,嘎嘎急~~~

求解~

2 个赞

需要一个header吧,我记得

没事,随机生成数字就行,信任你~

x-csrf-token

别啊,有很多水贴,我又要一一核对…… 核对完在生成随机数…… 过年了大佬。

2 个赞

必须让水王给你出方案

1 个赞

顶一下

不懂这个,学习一下

不对啊,我抓的包,直接提交就能获取到啊?

全部的数据吗?

单独提交的几页,会不会是你提交太快了,触发风控了

简单点把回复过的id都复制下来放Excel里去重后随机选一下也将就的,不要给自己压力
image


确实是风控了,换其他方法吧,这把全部帖子都扒出来了,确实有点频繁

以后会不会有官方的抽奖工具?@neo

就是太多了……

方法不对,我看看怎么改吧

@neo 始皇,结束的时候能不能给个参与用户的uuid 数据额,别的不要就要那个@人用的这个,然后我自己写一个抽奖把数据扔里,先抽,后去重。

我问问始皇吧,不行要一下吧,我刚刚都跑去写油侯了去爬了

应该不难 :rofl:

1 个赞