准备
- Python 3.11.6
- httpx 0.24.0
思路
F12浏览器调试-抓取POST请求-模仿发送请求-自动化
步骤
抓取POST
目标网站HiFiNi - 音乐磁场
F12开启开发者工具,点击签到按钮,筛选后发现仅有一个GET,推测是POST完毕之后自动重定向。
因此,在点击按钮后,立刻停止数据抓取即可。成功抓取到XHR。

点进去直接看payload:
1 2 3
| { "sign": "xxxxxxxxxxxxxx" }
|
响应为:
1 2 3 4
| { "code": "-1", "message": "今天已经签过啦!" }
|
构建请求
已经很久没用requests库了,我的项目现在都换成HTTPX了。这玩意是真好用,自带异步。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
import httpx from time import sleep
url = "https://www.hifini.com/sg_sign.htm"
post_content = { "sign": "xxxxxxxxxxxxxx" } headers = { "accept" : "text/plain, */*; q=0.01", "accept-encoding" : "gzip, deflate, br, zstd", "accept-language" : "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,en-GB;q=0.6", "content-length" : "69", "content-type" : "application/x-www-form-urlencoded; charset=UTF-8", "cookie" : "your_cookies", "origin" : "https://www.hifini.com", "referer" : "https://www.hifini.com/sg_sign.htm", "x-requested-with": "XMLHttpRequest" } cookies = { "bbs_sid" : "your_bbs_sid", "bbs_token": "your_bbs_token" }
with httpx.Client() as c: a = c.post( url=url, headers=headers, cookies=cookies, follow_redirects=True, data=post_content ) print(a.text)
|
1 2
| chmod +x main.py crontab -e
|
自己加个定时任务即可。
后记
2024.11.25 似乎过不了验证,没几天就掉了 >_<
2024.12.05 换GitHub Action的自动签到了:anduinnn/HiFiNi-Auto-CheckIn: HiFiNi - 音乐磁场签到助手