增加重试逻辑
This commit is contained in:
parent
7c0b14d0e5
commit
0ad9959341
29
qushuiyin.py
29
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*(.*?)</script>"
|
||||
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*(.*?)</script>"
|
||||
# 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*(.*?)</script>"
|
||||
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())
|
||||
|
|
Loading…
Reference in New Issue