跳到正文

休闲·娱乐

luogu自动打卡机

zqw1234约 5 分钟
原文
文章信息与版本

文章信息

收录
2026年5月3日
更新
2026年5月16日
篇幅
约 5 分钟

版本

  1. v1当前

1:代码

先是代码:

Python
import requests
import os
import sys

def luogu_punch():
    cookie_str="_uid=; __client_id=; C3VK="#自己改
    url="https://www.luogu.com.cn/index/ajax_punch"
    headers={
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
        "Cookie":cookie_str,
        "Referer":"https://www.luogu.com.cn/",
        "x-requested-with":"XMLHttpRequest"
    }
    with open("daka_log.txt", "a") as file:
        try:
            file.write("Attempting to connect to the Luogu server...\n")
            response= requests.get(url,headers=headers,timeout=10)
            # print(response)
            try:
                data=response.json()
            except:
                file.write("Failed to parse JSON\n")
                return
            if response.status_code==200:
                code=data.get('code')
                if code==200:
                    file.write(f"Punch successful, luck: {data}\n")
                elif code==201:
                    file.write("Today you have already punched in\n")
                else:
                    file.write(f"Failed: {data.get('message')}\n")
            else:
                file.write(f"Status code error: {response.status_code}\n")
        except Exception as e:
            file.write(f"An exception occurred: {e}\n")

if __name__=="__main__":
    luogu_punch()

代码cookie_str要填的uid大家肯定清楚,但__client_id,C3VK大家可能不知道,这里Google,Edge的方法差不多:\\

如何求__client_id,C3VK:


先打开自己的洛谷网站,按F12,打开开发者模式,点击最上方的“应用”一栏,点击左边一栏的cookie,便可看到,看不到可以刷新一下

P.S. 直接运行上面的Python代码会报错,需要pip install requests下载库后才能正常运行\\

2:使开电脑就可以打卡luogu

上面代码只能运行后打卡luogu,还不能做到全自动,由于我只有Windows系统,我先只出示Win11做法:

使用任务计划程序开机时打卡

在“开始”菜单中搜索“任务计划程序”,点那个有个像钟表的东西,进去点“创建任务”,名称自己定,位置不用管下面的选项框中这么选: 触发器: 操作栏中需要注意了,程序和脚本是你的Python.exe,可以在你下载的Python目录搜到,参数是你的运行文件,你的运行文件地址要加双引号,起始于选项是你的Python.exe下的目录\\ 做完之后,就实现了一个开机就可以打卡的luogu自动打卡机,虽然不那么完善,但这应该也是能做到最好的版本了\\

求大佬给个Mac的方案,xxs的第一篇文章,如有问题请大佬指出

原文