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())