From 0ad9959341472511953b26bf01cbed2b95f0b867 Mon Sep 17 00:00:00 2001 From: yezian Date: Wed, 7 Aug 2024 19:02:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=AF=95=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qushuiyin.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/qushuiyin.py b/qushuiyin.py index 2623280..d4bcecb 100644 --- a/qushuiyin.py +++ b/qushuiyin.py @@ -2,6 +2,7 @@ import re import json import requests import urllib.parse +import time proxy_url = "https://qsyapi.wishpal.cn/proxy?url=" @@ -27,13 +28,29 @@ class Video: } # Send request to get video info - response = requests.get( - f"https://www.iesdouyin.com/share/video/{video_id}", headers=headers - ) - pattern = r"window\._ROUTER_DATA\s*=\s*(.*?)" - matches = re.search(pattern, response.text, re.DOTALL) + # response = requests.get( + # f"https://www.iesdouyin.com/share/video/{video_id}", headers=headers + # ) - if not matches: + # pattern = r"window\._ROUTER_DATA\s*=\s*(.*?)" + # matches = re.search(pattern, response.text, re.DOTALL) + + # if not matches: + # return {"code": 201, "msg": "Parsing failed"} + + for attempt in range(10): + response = requests.get( + f"https://www.iesdouyin.com/share/video/{video_id}", headers=headers + ) + pattern = r"window\._ROUTER_DATA\s*=\s*(.*?)" + matches = re.search(pattern, response.text, re.DOTALL) + + if matches: + print(attempt) + break + else: + time.sleep(0.5) + else: return {"code": 201, "msg": "Parsing failed"} video_info = json.loads(matches.group(1).strip())