mirror of
https://github.com/imgyh/tiktok.git
synced 2025-06-04 05:49:16 +08:00
fix(tiktok): 修复主页作品接口获取数据不稳定, 增加X-Bogus接口限制
This commit is contained in:
parent
8f5afae34c
commit
62072e881e
21
TikTok.py
21
TikTok.py
@ -148,17 +148,16 @@ class TikTok(object):
|
|||||||
print("[ 错误 ]:模式选择错误, 仅支持post和like, 请检查后重新运行!\r")
|
print("[ 错误 ]:模式选择错误, 仅支持post和like, 请检查后重新运行!\r")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
while True:
|
||||||
res = requests.get(url=url, headers=self.headers)
|
# 接口不稳定, 有时服务器不返回数据, 需要重新获取
|
||||||
datadict = json.loads(res.text)
|
try:
|
||||||
print('[ 提示 ]:本次请求返回 ' + str(len(datadict["aweme_list"])) + ' 条数据')
|
res = requests.get(url=url, headers=self.headers)
|
||||||
except Exception as e:
|
datadict = json.loads(res.text)
|
||||||
print("[ 错误 ]:接口未返回数据, 请检查后重新运行!\r")
|
print('[ 提示 ]:本次请求返回 ' + str(len(datadict["aweme_list"])) + ' 条数据')
|
||||||
return None
|
if datadict is not None and datadict["status_code"] == 0:
|
||||||
|
break
|
||||||
if datadict["status_code"] != 0:
|
except Exception as e:
|
||||||
print("[ 错误 ]:接口返回状态码[" + datadict["status_code"] + "]异常, 请检查后重新运行!\r")
|
print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
||||||
return None
|
|
||||||
|
|
||||||
for aweme in datadict["aweme_list"]:
|
for aweme in datadict["aweme_list"]:
|
||||||
# 获取 aweme_id
|
# 获取 aweme_id
|
||||||
|
@ -60,6 +60,7 @@ class Urls(object):
|
|||||||
self.FOLLOW_FEED = 'https://www.douyin.com/aweme/v1/web/follow/feed/?'
|
self.FOLLOW_FEED = 'https://www.douyin.com/aweme/v1/web/follow/feed/?'
|
||||||
|
|
||||||
# X-Bogus Path
|
# X-Bogus Path
|
||||||
|
# 60 秒内,请求同一URI累计超过 600 次,封锁IP 300 秒
|
||||||
self.GET_XB_PATH = 'https://tiktok.199933.xyz/xb'
|
self.GET_XB_PATH = 'https://tiktok.199933.xyz/xb'
|
||||||
|
|
||||||
#######################################################################################
|
#######################################################################################
|
||||||
|
@ -55,11 +55,11 @@ class Utils(object):
|
|||||||
try:
|
try:
|
||||||
response = json.loads(requests.post(
|
response = json.loads(requests.post(
|
||||||
url= urls.GET_XB_PATH, data={"param" : url}, headers=headers).text)
|
url= urls.GET_XB_PATH, data={"param" : url}, headers=headers).text)
|
||||||
|
params = response["param"]
|
||||||
|
xb = response["X-Bogus"]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('[ 错误 ]:%s' % e)
|
print('[ 错误 ]:X-Bogus接口异常, 可能是访问流量高, 接口限流请稍等几分钟再次尝试')
|
||||||
|
return
|
||||||
params = response["param"]
|
|
||||||
xb = response["X-Bogus"]
|
|
||||||
|
|
||||||
return params #, xb
|
return params #, xb
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user