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

相关推荐
杨超越luckly20 分钟前
Agent 应用指南:基于 OurAirports 的中国机场设施数据可视化
python·html·github·可视化·机场设施
卷无止境22 分钟前
pytest 从零到实战:要想代码好,测试少不了
后端·python
吃糖的小孩37 分钟前
# RootGraph v1.5 收工:我给 QQ 机器人补上了聊天运行时的“黑匣子”
python
hangyuekejiGEO1 小时前
临沂GEO技术服务方案对比分析
大数据·人工智能·python
xin_yao_xin1 小时前
Conda 环境的 CUDA PATH 配置指南
开发语言·python·conda·cuda
Zhan8611242 小时前
西班牙股票行情数据API的WebSocket接入:IBEX35指数实时推送与数据清洗
python·websocket·网络协议
he___H2 小时前
基于LCEL的联想
开发语言·python·langchain
想会飞的蒲公英2 小时前
TF-IDF + 随机森林中文文本分类全链路实战:从训练脚本到 Flask API + Streamlit 前端
人工智能·pytorch·python·随机森林·分类·flask·tf-idf
FriendshipT2 小时前
Ultralytics:解读C3模块
人工智能·pytorch·python·深度学习·目标检测
极光代码工作室2 小时前
基于深度学习的异常行为检测系统
人工智能·python·深度学习·神经网络·机器学习