From c1289937965348876b7ea10ffda7c965d6f3de67 Mon Sep 17 00:00:00 2001 From: 3202307908 <3202307908@qq.com> Date: Fri, 9 May 2025 10:32:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 检测直播在线_roomId.py | 102 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 检测直播在线_roomId.py diff --git a/检测直播在线_roomId.py b/检测直播在线_roomId.py new file mode 100644 index 0000000..2fd6d79 --- /dev/null +++ b/检测直播在线_roomId.py @@ -0,0 +1,102 @@ +import os +import re +import time +import pickle +import requests +from datetime import datetime + + +session = requests.session() +def load_cookies_from_file(filename): + # 以二进制写入模式打开文件 + + with open(filename, 'rb') as f: + return pickle.load(f) + +# if os.path.isfile(f'{wjm}.pkl'): +# print(f'{wjm}.pkl文件存在') + +user_name = '' +with open(r'D:\job_demo\demo\测试\cookie_name.txt','r',encoding='utf-8') as f: + + user_name = f.read().split('|')[1].strip() +Cookie = load_cookies_from_file(r'D:\job_demo\demo\测试\MS4wLjABAAAAc9m4vmspNsSiYP348XRC-OLVqSXRn8Rdtl618fbzYag.pkl') +# print(Cookie) +# print(type(Cookie)) +cookies_dict = {c.name: c.value for c in Cookie} +cookie_str = "; ".join(f"{k}={v}" for k, v in cookies_dict.items()) + +def detect_live(): + # user_name = '' + # with open(r'D:\job_demo\demo\测试\cookie_name.txt','r',encoding='utf-8') as f: + + # user_name = f.read().split('|')[1].strip() + # Cookie = load_cookies_from_file(r'D:\job_demo\demo\测试\MS4wLjABAAAAc9m4vmspNsSiYP348XRC-OLVqSXRn8Rdtl618fbzYag.pkl') + # print(Cookie) + # print(type(Cookie)) + # cookies_dict = {c.name: c.value for c in Cookie} + # cookie_str = "; ".join(f"{k}={v}" for k, v in cookies_dict.items()) + # print(cookie_str) + # print(type(cookie_str)) + url = 'https://www.douyin.com/user/self?from_tab_name=live' + + headers = { + 'Connection': 'keep-alive', + 'Pragma': 'no-cache', + 'Cache-Control': 'no-cache', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36', + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'Accept-Encoding': 'gzip, deflate', + 'Accept-Language': 'zh-CN,zh;q=0.9', + } + res = session.get(url, headers=headers,cookies=Cookie) + + + while True: + if not res.status_code == 200: + print(datetime.now(),'请求失败,重试一次') + # app_edit(f'{datetime.now()}----请求失败,重试一次') + + #循环查询是否有开播的信息 + res = session.get(url,headers=headers,cookies=Cookie) + if 'const verify_data' in res.text: + print(datetime.now(), f'{user_name}--Cookie失效') + if '直播中' in res.text: + with open('index.html','w',encoding='utf-8') as f: + f.write(res.text) + # zburl = re.findall('