weixin_search.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import requests
  6. from applications.functions.common import sensitive_flag
  7. def wx_search(keys, sensitive_words):
  8. """
  9. WeChat search
  10. :param sensitive_words:
  11. :param keys:
  12. :return:
  13. """
  14. url = "http://8.217.190.241:8888/crawler/wei_xin/keyword"
  15. payload = json.dumps({
  16. "keyword": keys,
  17. "cursor": "0",
  18. "content_type": "video"
  19. })
  20. headers = {
  21. 'Content-Type': 'application/json'
  22. }
  23. response = requests.request("POST", url, headers=headers, data=payload).json()
  24. if response['msg'] == '未知错误':
  25. return []
  26. else:
  27. L = []
  28. if response['data']:
  29. video_list = response['data']['data']
  30. for video in video_list:
  31. try:
  32. video_info = video['items'][0]
  33. title = video_info['title']
  34. duration_str = video_info['duration']
  35. dr = int(duration_str.split(":")[0].strip()) + int(duration_str.split(":")[1].strip())
  36. if sensitive_flag(sensitive_words, title) and dr <= 300:
  37. L.append(video_info)
  38. else:
  39. continue
  40. except:
  41. pass
  42. return L