标题改编自:https://www.bilibili.com/video/BV176421u7o1。
本期主角:z_yq。
作者:bluewindde。
流光忆庭技术手册,由阿格莱雅赞助发表
Copyright (c) 2025 bluewindde
采用 CC BY-SA 4.0 International 协议 发布。
- upd on 2025-11-08 10:14:光锥技术。
- upd on 2025-11-20 21:59:QQ 防止撤回。
光锥技术
使用“打印为 PDF”功能保存精彩瞬间。
当精彩对话/对线还没结束时,请让子弹再飞一会儿。为了避免撤回/删除,可以使用“复制标签页”功能创建临时快照。
QQ 防止撤回
断网即可。
用户关注列表
背景 由于 zyq 取消关注+拉黑别人,应 AKPC 要求,「凯撒」决定实现此功能。
请求 https://www.luogu.com.cn/user/<uid>/following?page=<page>,data.users.result 字段中有关注列表。
需要一页一页请求,data.users.count 和 data.users.perPage 字段分别存储了关注数和每页返回的数量。
用户主页
由于洛谷主页无法在中国大陆访问,不提供获取方法。
请求的返回内容中有比用户主页更有趣的东西。
你是咖啡壶!
铁墓把大量 茶壶 伪装成服务器。如果你只有上面提到的知识,你多半会被夺走心识然后进入结算画面。
请使用 playwright 或其它爬虫技术对抗铁墓。
你可能需要:python3.13 -m playwright install chromium。
示例代码
由于使用了 ANSI 转义序列,建议在终端查看输出。
#!/usr/bin/python3.13
# 2y9.py
import json
import math
import time
import bs4
from playwright.sync_api import sync_playwright
assert __name__ == "__main__"
uid = 669171
with open("cookies.json") as file:
cookies = json.load(file)
with sync_playwright() as playwright:
browser = playwright.chromium.launch()
context = browser.new_context()
context.add_cookies(cookies)
page = context.new_page()
def get_json(url: str) -> str:
resp = page.request.get(url)
soup = bs4.BeautifulSoup(resp.text(), "lxml")
return json.loads(soup.find("script", { "id": "lentille-context" }).text)
data: dict = get_json(f"https://www.luogu.com.cn/user/{uid}/following?page=1")["data"]
username: str = data["user"]["name"]
user_slogan: str = data["user"]["slogan"]
user_introduction: str = data["user"]["introduction"]
per_page: int = data["users"]["perPage"]
count: int = data["users"]["count"]
ret: list = data["users"]["result"]
for i in range(2, math.ceil(count/per_page)+1):
time.sleep(0.1)
data: dict = get_json(f"https://www.luogu.com.cn/user/{uid}/following?page={i}")["data"]["users"]
ret += data["result"]
print(f"\033[34;1m{username} ({uid}) 的关注列表\033[0m ({len(ret)})")
follow = []
for x in ret:
print(f"- {x["name"]} ({x["uid"]})")
print(f" \033[2;3m{x["slogan"]}\033[0m")
follow.append(x["uid"])
print()
print(f"\033[34;1m{username} ({uid}) 的主页\033[0m")
print(f"\033[2;3m{user_slogan}\033[0m")
print()
print(user_introduction)
with open("2y9_homepage.md", "w") as file:
file.write(user_introduction)
with open("2y9_follow.json", "w") as file:
json.dump(follow, file)下一步
如果你希望投稿,欢迎私信我。