#!/usr/bin/env python3
"""
研究小红书创作中心的页面结构
"""
import asyncio
from browser.browser import BrowserManager
async def analyze_publish_page():
"""分析发布页面结构"""
print("="*60)
print("分析小红书创作中心页面结构")
print("="*60)
browser = BrowserManager(headless=False)
await browser.start()
try:
page = await browser.new_page()
print("\n1. 导航到创作中心...")
await page.goto("https://creator.xiaohongshu.com/publish/publish", timeout=60000)
await page.wait_for_load_state("load", timeout=60000)
await asyncio.sleep(5)
print("\n2. 分析页面结构...")
# 获取页面信息
page_structure = await page.evaluate("""
() => {
// 查找所有可能的上传区域
const uploadSelectors = [
'[class*="upload"]',
'[class*="Upload"]',
'input[type="file"]',
'[class*="dnd"]',
'[class*="drop"]'
];
const uploads = [];
uploadSelectors.forEach(selector => {
const elements = document.querySelectorAll(selector);
elements.forEach(el => {
uploads.push({
selector: selector,
className: el.className,
id: el.id,
tagName: el.tagName
});
});
});
// 查找标题输入框
const titleInputs = Array.from(document.querySelectorAll('input')).map(el => ({
placeholder: el.placeholder,
className: el.className,
id: el.id,
type: el.type
}));
// 查找内容输入区域
const contentAreas = Array.from(document.querySelectorAll('textarea, [contenteditable="true"]')).map(el => ({
tagName: el.tagName,
className: el.className,
id: el.id,
placeholder: el.placeholder || el.getAttribute('placeholder')
}));
// 查找发布按钮
const buttons = Array.from(document.querySelectorAll('button')).map(el => ({
text: el.textContent.trim(),
className: el.className,
id: el.id
}));
return {
url: window.location.href,
title: document.title,
uploads: uploads.slice(0, 5),
titleInputs: titleInputs.slice(0, 5),
contentAreas: contentAreas.slice(0, 5),
buttons: buttons.filter(b => b.text.includes('发布') || b.text.includes('提交')).slice(0, 5)
};
}
""")
print(f"\n URL: {page_structure['url']}")
print(f" 标题: {page_structure['title']}")
print(f"\n 上传区域 ({len(page_structure['uploads'])} 个):")
for upload in page_structure['uploads']:
print(f" - {upload['tagName']}: {upload['className'][:50]}")
print(f"\n 标题输入框 ({len(page_structure['titleInputs'])} 个):")
for input_field in page_structure['titleInputs']:
print(f" - placeholder: {input_field['placeholder']}")
print(f" class: {input_field['className'][:50]}")
print(f"\n 内容输入区域 ({len(page_structure['contentAreas'])} 个):")
for area in page_structure['contentAreas']:
print(f" - {area['tagName']}: {area['className'][:50]}")
print(f" placeholder: {area['placeholder']}")
print(f"\n 发布按钮 ({len(page_structure['buttons'])} 个):")
for button in page_structure['buttons']:
print(f" - 文本: {button['text']}")
print(f" class: {button['className'][:50]}")
# 截图保存
await page.screenshot(path="publish_page_structure.png", full_page=True)
print(f"\n ✓ 页面截图已保存: publish_page_structure.png")
print("\n3. 等待手动检查...")
print(" 请在浏览器中查看页面结构")
print(" 按 Ctrl+C 退出...")
await asyncio.sleep(300) # 等待 5 分钟
except KeyboardInterrupt:
print("\n\n用户中断")
except Exception as e:
print(f"\n✗ 错误: {e}")
import traceback
traceback.print_exc()
finally:
await browser.close()
print("\n" + "="*60)
if __name__ == "__main__":
asyncio.run(analyze_publish_page())