xiaohongshu_note_uploader/example_image.py

74 lines
2.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
图文笔记发布示例
这个示例展示如何发布一篇图文笔记到小红书
"""
import asyncio
from pathlib import Path
from publisher import XiaoHongShuImageNote
async def main():
"""发布图文笔记示例"""
print("=" * 70)
print("🌟 小红书图文笔记发布示例")
print("=" * 70)
# 配置笔记信息
title = "周末去哪玩 ✨"
content = "今天天气真好,推荐大家去公园走走~\n拍了好多美美的照片📸"
tags = ["#广州", "#周末出游", "#生活记录"]
# 图片路径支持1-9张图片
# 请替换为你自己的图片路径
image_paths = [
"../videos/image.jpg", # 示例图片
]
# Cookie文件路径
cookie_file = "cookies/account.json"
# 创建图文笔记上传器
print(f"\n📝 标题: {title}")
print(f"📷 图片数量: {len(image_paths)}")
print(f"🏷️ 标签: {', '.join(tags)}")
print(f"\n正在创建上传器...")
note = XiaoHongShuImageNote(
title=title,
content=content,
tags=tags,
image_paths=image_paths,
publish_date=0, # 0表示立即发布
account_file=cookie_file,
# location="广州塔", # 可选:添加地理位置
# cover_index=0, # 可选:指定封面图(默认第一张)
headless=False # 使用有头模式,可以看到操作过程
)
print("✅ 上传器创建成功")
print("\n💡 提示:")
print(" - 如果是首次使用,会自动打开浏览器让你扫码登录")
print(" - 浏览器会自动完成所有操作,请勿手动干预")
print(" - 整个过程大约需要30-60秒\n")
# 执行发布
try:
await note.main()
print("\n" + "=" * 70)
print("🎉 发布成功你可以打开小红书App查看你的笔记了")
print("=" * 70)
except Exception as e:
print(f"\n❌ 发布失败: {e}")
print("\n💡 故障排除:")
print(" 1. 检查网络连接")
print(" 2. 确认图片文件存在")
print(" 3. 查看错误截图(如果有)")
if __name__ == "__main__":
# 运行示例
asyncio.run(main())