import asyncio import httpx class DanMu(): def __init__(self): super().__init__() async def tencent(self, vid): async with httpx.AsyncClient() as client: base_url = f"https://dm.video.qq.com/barrage/base/{vid}" res = await client.get(base_url) if res.status_code == 200: json_data = res.json() segment_data = json_data.get("segment_index") # data index max_index = len(segment_data) - 1 # max end page max_page = max_index * 30000 # Calculate the amount of data acquired per page per_count = 20000 / max_index for i in range(0, 1): print(i) else: # 处理请求失败的情况 return None async def main(): dm = DanMu() result = await dm.tencent("p0047s9euki") if __name__ == "__main__": loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close()