test_xhs_search.py 949 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. """
  2. 测试小红书渠道的 search_posts 接口
  3. """
  4. import asyncio
  5. import sys
  6. sys.path.insert(0, '/root/Agent')
  7. from agent.tools.builtin.search import search_posts
  8. async def test_xhs_search():
  9. """测试小红书搜索"""
  10. print("开始测试小红书渠道搜索...")
  11. print("-" * 50)
  12. # 测试搜索
  13. result = await search_posts(
  14. keyword="Python编程",
  15. channel="xhs",
  16. cursor="0",
  17. max_count=5
  18. )
  19. print(f"标题: {result.title}")
  20. print(f"是否有错误: {result.error is not None}")
  21. if result.error:
  22. print(f"错误信息: {result.error}")
  23. else:
  24. print(f"输出长度: {len(result.output)} 字符")
  25. print(f"图片数量: {len(result.images) if result.images else 0}")
  26. print("\n搜索结果:")
  27. print(result.output[:500]) # 只打印前500字符
  28. return result
  29. if __name__ == "__main__":
  30. result = asyncio.run(test_xhs_search())