feat: 增加 xiaohongshu 的登录和发布相关脚本

This commit is contained in:
Edan's Win11
2025-06-03 23:02:47 +08:00
parent 8be9a09432
commit 86fb7f6563
12 changed files with 535 additions and 22 deletions
+26 -12
View File
@@ -71,22 +71,36 @@ async def cookie_auth_ks(account_file):
return True
async def cookie_auth_xhs(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
page = await context.new_page()
# 访问指定的 URL
await page.goto("https://creator.xiaohongshu.com/creator-micro/content/upload")
try:
await page.wait_for_url("https://creator.xiaohongshu.com/creator-micro/content/upload", timeout=5000)
except:
print("[+] 等待5秒 cookie 失效")
await context.close()
await browser.close()
return False
# 2024.06.17 抖音创作者中心改版
if await page.get_by_text('手机号登录').count() or await page.get_by_text('扫码登录').count():
print("[+] 等待5秒 cookie 失效")
return False
else:
print("[+] cookie 有效")
return True
async def check_cookie(type,file_path):
match type:
# 小红书
case 1:
config = configparser.RawConfigParser()
config.read(Path(BASE_DIR / "cookiesFile" / file_path))
cookies = config['account1']['cookies']
xhs_client = XhsClient(cookies, sign=sign_local, timeout=60)
# auth cookie
# 注意:该校验cookie方式可能并没那么准确
try:
xhs_client.get_video_first_frame_image_id("3214")
except:
print("cookie 失效")
return True
return await cookie_auth_xhs(Path(BASE_DIR / "cookiesFile" / file_path))
# 视频号
case 2:
return await cookie_auth_tencent(Path(BASE_DIR / "cookiesFile" / file_path))
@@ -99,5 +113,5 @@ async def check_cookie(type,file_path):
case _:
return False
# a = asyncio.run(check_cookie(4,"3a6cfdc0-3d51-11f0-8507-44e51723d63c.json"))
# a = asyncio.run(check_cookie(1,"3a6cfdc0-3d51-11f0-8507-44e51723d63c.json"))
# print(a)