Python实现定时对网站进行签到

文章目录

一、步骤

首先打开我们需要签到的网站,使用Chrome浏览器的F12快捷键(或通过鼠标右键菜单"检查")打开浏览器的开发者工具,点击 Network 查看所有加载的请求。

如下方动图所示,这个时候我们手动点击签到,就会发现出现了一个新的post请求(checkin),不出所料这便是我们签到的请求。

点击签到抓取请求

  • 如下图所示,右键复制网络抓到的网络请checkin(可以看到是一个POST请求)求为cURL(bash)。

复制cURL(bash)

将刚刚复制的内容,填写该网站左侧,右侧同时生成了对应的 python requests 代码。

剩下的事就很简单了,只需要每天定时执行该代码(模拟发起post签到请求)就可以实现该网站签到。

python 复制代码
#!/usr/bin/python3

# method: https://cloud.tencent.com/developer/article/2177163
import requests

cookies = {
    'cf_clearance': 'oIGaNwZsFwuFhnIb6lBbxpMdL_3wSRl1JDcIO5KMbh8-1698975513-0-1-95a9cc35.4d28a2e4.26b7c013-0.2.1698975513',
}

headers = {
    'authority': 'ai-panda.xyz',
    'accept': '*/*',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    # Already added when you pass json=
    # 'content-type': 'application/json',
    # 'cookie': 'cf_clearance=oIGaNwZsFwuFhnIb6lBbxpMdL_3wSRl1JDcIO5KMbh8-1698975513-0-1-95a9cc35.4d28a2e4.26b7c013-0.2.1698975513',
    'origin': 'https://ai-panda.xyz',
    'referer': 'https://ai-panda.xyz/login',
    'sec-ch-ua': '"Chromium";v="118", "Microsoft Edge";v="118", "Not=A?Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'token': 'undefined',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.76',
}

json_data = {
    'account': 'jiwangreal@163.com',
    'password': 'xxxxx',
    'invite_code': '',
}


def LoginJob():
    print('start login url function')
    response = requests.post('https://ai-panda.xyz/api/login',
                             cookies=cookies, headers=headers, json=json_data)
    g_url = ''
    for key, value in headers.items():
        if key == 'origin':
            print(value)

    loginStats = response.status_code
    print(f'url: {g_url} login status {loginStats}')

    if loginStats == 200:
        print('login success!')
    else:
        print('login failure')


def SignIn():
    print('wait sign in implement')


def TestPrint():
    print('TestPrint')


def PerliticPerformJob():
    import schedule
    import time
    schedule.every().day.at("09:00").do(LoginJob)
    # schedule.every(1).seconds.do(TestPrint)

    while True:
        schedule.run_pending()
        time.sleep(1)


if __name__ == '__main__':
    PerliticPerformJob()

Reference

相关推荐
单片机学习之路4 分钟前
【Python】输入input函数
开发语言·python
不屈的铝合金5 分钟前
Python入门:输入输出(I/O)指南
windows·python·i/o·input·print·输入输出
lifallen23 分钟前
Flink Agent 与 Checkpoint:主循环闭环与 Mailbox 事件驱动模型
java·大数据·人工智能·python·语言模型·flink
平安的平安23 分钟前
Python 构建AI多智能体系统:让三个 AI 协作完成复杂任务
开发语言·人工智能·python
曲幽26 分钟前
FastAPI + Vue 前后端分离实战:我的项目结构“避坑指南”
python·vue·fastapi·web·vite·proxy·cors·env
Kapaseker29 分钟前
Python 提速 — 惰性导入
python
杜子不疼.34 分钟前
Python + Ollama 本地跑大模型:零成本打造私有 AI 助手
开发语言·c++·人工智能·python
李昊哲小课34 分钟前
pip缓存配置
python·缓存·pip
belldeep35 分钟前
python:介绍 UV 安装,如何使用 UV 安装配置 OpenHarness
windows·python·环境变量·uv
理想三旬39 分钟前
Numpy 数据库
python·机器学习·numpy