fix(tiktok): 修复主页作品接口获取数据不稳定, 增加X-Bogus接口限制

This commit is contained in:
imgyh 2023-02-20 13:59:53 +08:00
parent 8f5afae34c
commit 62072e881e
3 changed files with 15 additions and 15 deletions

View File

@ -148,17 +148,16 @@ class TikTok(object):
print("[ 错误 ]:模式选择错误, 仅支持post和like, 请检查后重新运行!\r")
return None
try:
res = requests.get(url=url, headers=self.headers)
datadict = json.loads(res.text)
print('[ 提示 ]:本次请求返回 ' + str(len(datadict["aweme_list"])) + ' 条数据')
except Exception as e:
print("[ 错误 ]:接口未返回数据, 请检查后重新运行!\r")
return None
if datadict["status_code"] != 0:
print("[ 错误 ]:接口返回状态码[" + datadict["status_code"] + "]异常, 请检查后重新运行!\r")
return None
while True:
# 接口不稳定, 有时服务器不返回数据, 需要重新获取
try:
res = requests.get(url=url, headers=self.headers)
datadict = json.loads(res.text)
print('[ 提示 ]:本次请求返回 ' + str(len(datadict["aweme_list"])) + ' 条数据')
if datadict is not None and datadict["status_code"] == 0:
break
except Exception as e:
print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
for aweme in datadict["aweme_list"]:
# 获取 aweme_id

View File

@ -60,6 +60,7 @@ class Urls(object):
self.FOLLOW_FEED = 'https://www.douyin.com/aweme/v1/web/follow/feed/?'
# X-Bogus Path
# 60 秒内,请求同一URI累计超过 600 次,封锁IP 300 秒
self.GET_XB_PATH = 'https://tiktok.199933.xyz/xb'
#######################################################################################

View File

@ -55,11 +55,11 @@ class Utils(object):
try:
response = json.loads(requests.post(
url= urls.GET_XB_PATH, data={"param" : url}, headers=headers).text)
params = response["param"]
xb = response["X-Bogus"]
except Exception as e:
print('[ 错误 ]:%s' % e)
params = response["param"]
xb = response["X-Bogus"]
print('[ 错误 ]:X-Bogus接口异常, 可能是访问流量高, 接口限流请稍等几分钟再次尝试')
return
return params #, xb