ks_pc_keyword.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # import time
  2. #
  3. # import requests
  4. # import json
  5. #
  6. # from common import Common, AliyunLogger, Feishu, Material
  7. # from common.sql_help import sqlCollect
  8. # from common.userAgent import get_random_user_agent
  9. #
  10. #
  11. # class KsPcKeyword:
  12. # @classmethod
  13. # def get_key_word(cls, keyword, task_mark, mark, channel_id, name, task):
  14. # list = []
  15. # url = "https://www.kuaishou.com/graphql"
  16. #
  17. # payload = json.dumps({
  18. # "operationName": "visionSearchPhoto",
  19. # "variables": {
  20. # "keyword": keyword,
  21. # "pcursor": "",
  22. # "page": "search"
  23. # },
  24. # "query": "fragment photoContent on PhotoEntity {\n __typename\n id\n duration\n caption\n originCaption\n likeCount\n viewCount\n commentCount\n realLikeCount\n coverUrl\n photoUrl\n photoH265Url\n manifest\n manifestH265\n videoResource\n coverUrls {\n url\n __typename\n }\n timestamp\n expTag\n animatedCoverUrl\n distance\n videoRatio\n liked\n stereoType\n profileUserTopPhoto\n musicBlocked\n riskTagContent\n riskTagUrl\n}\n\nfragment recoPhotoFragment on recoPhotoEntity {\n __typename\n id\n duration\n caption\n originCaption\n likeCount\n viewCount\n commentCount\n realLikeCount\n coverUrl\n photoUrl\n photoH265Url\n manifest\n manifestH265\n videoResource\n coverUrls {\n url\n __typename\n }\n timestamp\n expTag\n animatedCoverUrl\n distance\n videoRatio\n liked\n stereoType\n profileUserTopPhoto\n musicBlocked\n riskTagContent\n riskTagUrl\n}\n\nfragment feedContent on Feed {\n type\n author {\n id\n name\n headerUrl\n following\n headerUrls {\n url\n __typename\n }\n __typename\n }\n photo {\n ...photoContent\n ...recoPhotoFragment\n __typename\n }\n canAddComment\n llsid\n status\n currentPcursor\n tags {\n type\n name\n __typename\n }\n __typename\n}\n\nquery visionSearchPhoto($keyword: String, $pcursor: String, $searchSessionId: String, $page: String, $webPageArea: String) {\n visionSearchPhoto(keyword: $keyword, pcursor: $pcursor, searchSessionId: $searchSessionId, page: $page, webPageArea: $webPageArea) {\n result\n llsid\n webPageArea\n feeds {\n ...feedContent\n __typename\n }\n searchSessionId\n pcursor\n aladdinBanner {\n imgUrl\n link\n __typename\n }\n __typename\n }\n}\n"
  25. # })
  26. # cookie = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "快手搜索-cookie")
  27. # headers = {
  28. # 'Accept-Language': 'zh-CN,zh;q=0.9',
  29. # 'Cache-Control': 'no-cache',
  30. # 'Connection': 'keep-alive',
  31. # 'Origin': 'https://www.kuaishou.com',
  32. # 'Pragma': 'no-cache',
  33. # 'User-Agent': get_random_user_agent("pc"),
  34. # 'accept': '*/*',
  35. # 'content-type': 'application/json',
  36. # 'Cookie': cookie
  37. # }
  38. # try:
  39. # time.sleep(3)
  40. # # 代理信息
  41. # proxy = "http://spkbt3wnzw:cx6R=v5mQuBgqsQ4o7@cn.visitxiangtan.com:30000"
  42. # proxies = {
  43. # "http": proxy,
  44. # "https": proxy
  45. # }
  46. # response = requests.request("POST", url, headers=headers, data=payload, proxies=proxies)
  47. # text = response.text
  48. # if text:
  49. # response_dict = json.loads(text)
  50. # result = response_dict.get('result', None)
  51. # if result:
  52. # log_type = ['liukunyu', 'wangxueke', 'xinxin']
  53. # mark_name = ['刘坤宇', '王雪珂', '信欣']
  54. # Feishu.bot(log_type, '快手关键词搜索', f'快手关键词搜索cookie过期,请及时更换', mark_name)
  55. # time.sleep(10)
  56. # return list
  57. # response = response.json()
  58. # data_list = response['data']['visionSearchPhoto']['feeds']
  59. # for data in data_list:
  60. # data = data['photo']
  61. # photo_id = data["id"]
  62. # status = sqlCollect.is_used(task_mark, photo_id, mark, channel_id)
  63. #
  64. # view_count = data["viewCount"] if "viewCount" in data and data["viewCount"] else 0
  65. # like_count = data["likeCount"] if "likeCount" in data and data["likeCount"] else 0
  66. # like_count = cls.convert_to_number(like_count)
  67. # video_percent = '%.4f' % (int(like_count) / int(view_count))
  68. # special = 0.015
  69. # old_title = data["caption"] # 标题
  70. # duration = data["duration"]
  71. # duration = int(duration) / 1000
  72. # video_url = data["photoUrl"]
  73. # image_url = data["coverUrl"]
  74. # log_data = f"user:{keyword},,video_id:{photo_id},,video_url:{video_url},original_title:{old_title},,like_count:{like_count},,view_count:{view_count},,duration:{duration}"
  75. # AliyunLogger.logging(channel_id, name, keyword, photo_id, "扫描到一条视频", "2001", log_data)
  76. # if status:
  77. # AliyunLogger.logging(channel_id, name, keyword, photo_id, "该视频已改造过", "2001", log_data)
  78. # continue
  79. # if int(view_count) < 1000:
  80. # AliyunLogger.logging(channel_id, name, keyword, photo_id, f"不符合规则:浏览小于1000", "2003", log_data)
  81. # Common.logger("ks-key-word").info(
  82. # f"不符合规则:{task_mark},用户主页id:{keyword},视频id{photo_id} ,浏览:{view_count},浏览{view_count} ,时长:{int(duration)} ")
  83. # continue
  84. # if float(video_percent) < special:
  85. # AliyunLogger.logging(channel_id, name, keyword, photo_id, f"不符合规则:点赞/浏览{special}", "2003", log_data)
  86. # Common.logger("ks-key-word").info(
  87. # f"不符合规则:{task_mark},用户主页id:{keyword},视频id{photo_id} ,浏览:{view_count},浏览{view_count} ,时长:{int(duration)} ")
  88. # continue
  89. # if int(duration) < 30 or int(duration) > 600:
  90. # AliyunLogger.logging(channel_id, name, keyword, photo_id,
  91. # f"不符合规则:时长不符合规则大于600秒/小于30秒", "2003",
  92. # log_data)
  93. #
  94. # Common.logger("ks-key-word").info(
  95. # f"不符合规则:{task_mark},用户主页id:{keyword},视频id{photo_id} ,浏览:{view_count},浏览{view_count} ,时长:{int(duration)} ")
  96. # continue
  97. # AliyunLogger.logging(channel_id, name, keyword, photo_id, "符合规则等待改造", "2004", log_data)
  98. # all_data = {"video_id": photo_id, "cover": image_url, "video_url": video_url,
  99. # "rule": '',
  100. # "old_title": old_title}
  101. # list.append(all_data)
  102. # return list
  103. # except Exception as exc:
  104. # Common.logger("ks-key-word").info(f"快手搜索词{keyword}获取失败{exc}\n")
  105. # return list
  106. #
  107. # @classmethod
  108. # def convert_to_number(cls, value):
  109. # if value.endswith("万"):
  110. # return float(value[:-1]) * 10000 # 去掉“万”并乘以 10000
  111. # return int(value) # 处理其他格式
  112. #
  113. #
  114. # if __name__ == '__main__':
  115. # keyword = '毛主席故居'
  116. # task_mark = '1'
  117. # mark = 'pl-gjc'
  118. # channel_id = '快手搜索'
  119. # name = '1'
  120. # task = {'combo': ['最新发布', '近1日', '1分钟内']}
  121. # KsPcKeyword.get_key_word(keyword, task_mark, mark, channel_id, name, task)