# -*- coding: utf-8 -*- # @Author: wangkun # @Time: 2022/11/23 import time import requests from main.common import Common from main.feishu_lib import Feishu class Demo: @classmethod def get_sheet(cls, log_type, crawler, sheetid): sheet = Feishu.get_values_batch(log_type, crawler, sheetid) print(sheet) @classmethod def publish_time(cls): time1 = '发布时间:2022年11月20日' time2 = time1.replace('发布时间:', '').replace('年', '/').replace('月', '/').replace('日', '') print(time2) time3 = int(time.mktime(time.strptime(time2, "%Y/%m/%d"))) print(time3) @classmethod def get_video_url(cls, log_type, video_id): url = 'https://haokan.hao123.com/v?' params = { 'vid': video_id, '_format': 'json', } headers = { 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Cookie': 'PC_TAB_LOG=video_details_page; COMMON_LID=b0be69dd9fcae328d06935bd40f615cd; Hm_lvt_4aadd610dfd2f5972f1efee2653a2bc5=1669029953; hkpcvideolandquery=%u82CF%u5DDE%u6700%u5927%u7684%u4E8C%u624B%u8F66%u8D85%u5E02%uFF0C%u8F6C%u4E00%u8F6C%u91CC%u8FB9%u8C6A%u8F66%u592A%u591A%u4E86%uFF0C%u4EF7%u683C%u66F4%u8BA9%u6211%u5403%u60CA%uFF01; Hm_lpvt_4aadd610dfd2f5972f1efee2653a2bc5=1669875695; ariaDefaultTheme=undefined; reptileData=%7B%22data%22%3A%22636c55e0319da5169a60acec4a264a35c10862f8abfe2f2cc32c55eb6b0ab4de0efdfa115ea522d6d4d361dea07feae2831d3e2c16ed6b051c611ffe5aded6c9f852501759497b9fbd2132a2160e1e40e5845b41f78121ddcc3288bd077ae4e8%22%2C%22key_id%22%3A%2230%22%2C%22sign%22%3A%22f6752aac%22%7D; RT="z=1&dm=hao123.com&si=uc0q7wnm4w&ss=lb4otu71&sl=j&tt=av0&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=1rdw&cl=7v6c"', 'Pragma': 'no-cache', 'Referer': 'https://haokan.hao123.com/v?vid=10623278258033022286&pd=pc&context=', 'sec-ch-ua': '"Microsoft Edge";v="107", "Chromium";v="107", "Not=A?Brand";v="24"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"macOS"', 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-origin', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62', } r = requests.get(url=url, headers=headers, params=params) if r.status_code != 200: Common.logger(log_type).info(f'get_video_url_response:{r.text}') elif r.json()['errno'] != 0 or len(r.json()['data']) == 0: Common.logger(log_type).info(f'get_video_url_response:{r.json()}') else: clarityUrl = r.json()['data']['apiData']['curVideoMeta']['clarityUrl'] video_url = r.json()['data']['apiData']['curVideoMeta']['clarityUrl'][len(clarityUrl)-1]['url'] return video_url if __name__ == '__main__': # Demo.get_sheet('demo', 'haokan', '7f05d8') # Demo.publish_time() Demo.get_video_url('demo', '10377041690614321392') pass