search.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """
  2. 搜索API
  3. """
  4. from flask import Blueprint
  5. from flask import request
  6. import api
  7. from huitun import HuiTunBrowser
  8. from util import lock_util
  9. from xhs import XhsBrowser
  10. from playwright.sync_api import Playwright, sync_playwright
  11. search_opt = Blueprint('search', __name__)
  12. @search_opt.route('/note', methods=["POST"])
  13. def search_note():
  14. """
  15. 根据关键字搜索抖音笔记
  16. :return:
  17. """
  18. request_body = request.json
  19. playwright = sync_playwright().start()
  20. browser = HuiTunBrowser(lock_util.get_idle_phone('huitun'), playwright)
  21. result = browser.search_note(request_body.get('tagName'), request_body.get('searchLimit'))
  22. xhs_browser = XhsBrowser(lock_util.get_idle_phone('xhs'), playwright)
  23. result = xhs_browser.polish_huitun_note(result)
  24. playwright.stop()
  25. return api.success(result)
  26. @search_opt.route('/note-info', methods=["POST"])
  27. def search_note_info():
  28. """
  29. 根据笔记id获取笔记详情
  30. :return:
  31. """
  32. with sync_playwright() as playwright:
  33. request_body = request.json
  34. xhs_browser = XhsBrowser(lock_util.get_idle_phone('xhs'), playwright=playwright)
  35. xhs_browser.__init_browser__()
  36. note = xhs_browser.get_note(request_body.get('noteId'))
  37. return api.success(note)