# -*- coding: utf-8 -*- # @Author: wangkun # @Time: 2022/5/16 import datetime import time from datetime import timedelta import requests import urllib3 proxies = {"http": None, "https": None} class Demo: # 查询视频详情的各项数据 @classmethod def video_detail_info(cls, user_id, user_mid, video_id): url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id" headers = { "x-b3-traceid": "bd267349bf41b", "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701", "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9", "content-type": "application/json", "Accept-Encoding": "gzip,compress,br,deflate", "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)' ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 ' 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN', "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html" } data = { "play_src": "1", "profile_id": int(user_id), "profile_mid": int(user_mid), "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/" "!400x400r/crop/400x400/interlace/1/format/jpg", "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail" "/!80x80r/crop/80x80/interlace/1/format/jpg", "share_width": 625, "share_height": 500, "no_comments": True, "no_follow": True, "vid": video_id, "hot_l1_comment": True, "token": "90747742180aeb22c0fe3a3c6a38f3d9", "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9", "proj": "ma", "wx_ver": "8.0.20", "code_ver": "3.62.0", "log_common_params": { "e": [{ "data": { "page": "dynamicSharePage" } }], "ext": { "brand": "iPhone", "device": "iPhone 11", "os": "iOS 14.7.1", "weixinver": "8.0.20", "srcver": "2.24.3", "net": "wifi", "scene": "1089" }, "pj": "1", "pf": "2", "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29" } } try: urllib3.disable_warnings() r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False) video_title = r.json()["data"]["title"] video_id = r.json()["data"]["vid"] video_play_cnt = r.json()["data"]["play_pv"] video_duration = int(r.json()["data"]["du"])/1000 video_url = r.json()["data"]["v_url"] video_send_time = r.json()["data"]["t"] print(f"video_title:{video_title}") print(f"video_id:{video_id}") print(f"video_play_cnt:{video_play_cnt}") print(f"video_duration:{video_duration}") print(f'video_send_time:{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time)/1000))}') print(f"video_url:{video_url}") except Exception as e: print(e) # 时间 @classmethod def times(cls): before_yesterday = (datetime.date.today() + timedelta(days=-2)).strftime("%Y/%m/%d %H:%M:%S") before_yesterday = time.strptime(before_yesterday, "%Y/%m/%d %H:%M:%S") before_yesterday = int(time.mktime(before_yesterday)) print(before_yesterday) print(type(before_yesterday)) if __name__ == "__main__": demo = Demo() # demo.video_detail_info("44373353", "1161593420", "4572205769") # demo.times() print(1654744346-1654605576)