mirror of
https://github.com/imgyh/tiktok.git
synced 2025-09-28 10:30:07 +08:00
fix(tiktok): 修复主页作品接口与直播接口
This commit is contained in:
parent
4077fde295
commit
909b9f3f1c
15
TikTok.py
15
TikTok.py
@ -34,7 +34,7 @@ class TikTok(object):
|
|||||||
self.headers = {
|
self.headers = {
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
|
||||||
'referer': 'https://www.douyin.com/',
|
'referer': 'https://www.douyin.com/',
|
||||||
'Cookie': 'msToken=%s;odin_tt=324fb4ea4a89c0c05827e18a1ed9cf9bf8a17f7705fcc793fec935b637867e2a5a9b8168c885554d029919117a18ba69;' % self.utils.generate_random_str(107)
|
'Cookie': '__ac_nonce=063f2dac800532463833e; s_v_web_id=verify_lec77mky_PdkXTRSx_VwYB_4B32_BT52_CM9JP3QLtWnX; msToken=%s;odin_tt=324fb4ea4a89c0c05827e18a1ed9cf9bf8a17f7705fcc793fec935b637867e2a5a9b8168c885554d029919117a18ba69;' % self.utils.generate_random_str(107)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ class TikTok(object):
|
|||||||
print("[ 提示 ]:正在进行第 " + str(times) + " 次请求...\r")
|
print("[ 提示 ]:正在进行第 " + str(times) + " 次请求...\r")
|
||||||
if mode == "post":
|
if mode == "post":
|
||||||
url = self.urls.USER_POST + self.utils.getXbogus(
|
url = self.urls.USER_POST + self.utils.getXbogus(
|
||||||
url=f'sec_user_id={sec_uid}&count={count}&max_cursor={max_cursor}&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333')
|
url=f'sec_uid={sec_uid}&count={count}&max_cursor={max_cursor}')
|
||||||
elif mode == "like":
|
elif mode == "like":
|
||||||
url = self.urls.USER_FAVORITE_A + self.utils.getXbogus(
|
url = self.urls.USER_FAVORITE_A + self.utils.getXbogus(
|
||||||
url=f'sec_user_id={sec_uid}&count={count}&max_cursor={max_cursor}&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333')
|
url=f'sec_user_id={sec_uid}&count={count}&max_cursor={max_cursor}&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333')
|
||||||
@ -151,12 +151,13 @@ class TikTok(object):
|
|||||||
try:
|
try:
|
||||||
res = requests.get(url=url, headers=self.headers)
|
res = requests.get(url=url, headers=self.headers)
|
||||||
datadict = json.loads(res.text)
|
datadict = json.loads(res.text)
|
||||||
|
print('[ 提示 ]:本次请求返回 ' + str(len(datadict["aweme_list"])) + ' 条数据')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("[ 错误 ]:接口未返回数据, 请检查后重新运行!\r")
|
print("[ 错误 ]:接口未返回数据, 请检查后重新运行!\r")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not datadict["aweme_list"]:
|
if datadict["status_code"] != 0:
|
||||||
print("[ 错误 ]:未找到数据, 请检查后重新运行!\r")
|
print("[ 错误 ]:接口返回状态码[" + datadict["status_code"] + "]异常, 请检查后重新运行!\r")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for aweme in datadict["aweme_list"]:
|
for aweme in datadict["aweme_list"]:
|
||||||
@ -170,7 +171,7 @@ class TikTok(object):
|
|||||||
max_cursor = datadict["max_cursor"]
|
max_cursor = datadict["max_cursor"]
|
||||||
|
|
||||||
# 退出条件
|
# 退出条件
|
||||||
if datadict["has_more"] != 1:
|
if datadict["has_more"] == 0 or datadict["has_more"] == False:
|
||||||
print("[ 提示 ]:所有作品数据获取完成...\r\n")
|
print("[ 提示 ]:所有作品数据获取完成...\r\n")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -184,9 +185,9 @@ class TikTok(object):
|
|||||||
|
|
||||||
live_api = 'https://live.douyin.com/webcast/room/web/enter/?aid=6383&device_platform=web&web_rid=%s' % (web_rid)
|
live_api = 'https://live.douyin.com/webcast/room/web/enter/?aid=6383&device_platform=web&web_rid=%s' % (web_rid)
|
||||||
|
|
||||||
# 必须用这个 headers
|
|
||||||
headers = {
|
headers = {
|
||||||
'Cookie': 'msToken=tsQyL2_m4XgtIij2GZfyu8XNXBfTGELdreF1jeIJTyktxMqf5MMIna8m1bv7zYz4pGLinNP2TvISbrzvFubLR8khwmAVLfImoWo3Ecnl_956MgOK9kOBdwM=; odin_tt=6db0a7d68fd2147ddaf4db0b911551e472d698d7b84a64a24cf07c49bdc5594b2fb7a42fd125332977218dd517a36ec3c658f84cebc6f806032eff34b36909607d5452f0f9d898810c369cd75fd5fb15; ttwid=1%7CfhiqLOzu_UksmD8_muF_TNvFyV909d0cw8CSRsmnbr0%7C1662368529%7C048a4e969ec3570e84a5faa3518aa7e16332cfc7fbcb789780135d33a34d94d2'
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
|
||||||
|
'cookie' : '__ac_nonce=063f2f2fe002b0c1cf5a3; ttwid=1|_P0qI1eym6Of_Wz2s3FhDRThixb46o2hSYqHFIcdaHM|1676866302|3dd715d4512ff13abbd1aaedc19257b8bfe55b2bbbcad6a95de237776729ba54'
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -56,10 +56,13 @@ if __name__ == "__main__":
|
|||||||
# 图集
|
# 图集
|
||||||
# python TikTokCommand.py -l https://v.douyin.com/BugrFTN/ -p /mnt/c/project/test2
|
# python TikTokCommand.py -l https://v.douyin.com/BugrFTN/ -p /mnt/c/project/test2
|
||||||
# .\TikTokCommand.exe -l https://v.douyin.com/BugrFTN/ -p .\test2
|
# .\TikTokCommand.exe -l https://v.douyin.com/BugrFTN/ -p .\test2
|
||||||
# 主页作品
|
# 主页作品(视频)
|
||||||
# python TikTokCommand.py -l https://v.douyin.com/BupCppt/ -p /mnt/c/project/test3
|
# python TikTokCommand.py -l https://v.douyin.com/BupCppt/ -p /mnt/c/project/test3
|
||||||
# .\TikTokCommand.exe -l https://v.douyin.com/BupCppt/ -p .\test3
|
# .\TikTokCommand.exe -l https://v.douyin.com/BupCppt/ -p .\test3
|
||||||
# 主页喜欢
|
# 主页作品(视频与图集混合)
|
||||||
# python TikTokCommand.py -l https://v.douyin.com/BusJrfr/ -p /mnt/c/project/test4 -M like
|
# python TikTokCommand.py -l https://v.douyin.com/B72pdU5/ -p /mnt/c/project/test4
|
||||||
# .\TikTokCommand.exe -l https://v.douyin.com/BusJrfr/ -p .\test4 -M like
|
# .\TikTokCommand.exe -l https://v.douyin.com/B72pdU5/ -p .\test4
|
||||||
|
# 主页喜欢(视频)
|
||||||
|
# python TikTokCommand.py -l https://v.douyin.com/B72QgDw/ -p /mnt/c/project/test5 -M like
|
||||||
|
# .\TikTokCommand.exe -l https://v.douyin.com/B72QgDw/ -p .\test5 -M like
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
@ -28,7 +28,12 @@ class Urls(object):
|
|||||||
self.USER_DETAIL = 'https://www.douyin.com/aweme/v1/web/user/profile/other/?'
|
self.USER_DETAIL = 'https://www.douyin.com/aweme/v1/web/user/profile/other/?'
|
||||||
|
|
||||||
# 用户作品
|
# 用户作品
|
||||||
self.USER_POST = 'https://www.douyin.com/aweme/v1/web/aweme/post/?'
|
# cookies 暂时只需要 __ac_nonce, s_v_web_id两个参数
|
||||||
|
# url 暂时不需要携带 msToken, X-Bogus, _signature
|
||||||
|
# 每次返回数据很少
|
||||||
|
self.USER_POST = 'https://m.douyin.com/web/api/v2/aweme/post/?'
|
||||||
|
# 2023/02/19 失效
|
||||||
|
# self.USER_POST = 'https://www.douyin.com/aweme/v1/web/aweme/post/?'
|
||||||
|
|
||||||
# 作品信息
|
# 作品信息
|
||||||
self.POST_DETAIL = 'https://www.douyin.com/aweme/v1/web/aweme/detail/?'
|
self.POST_DETAIL = 'https://www.douyin.com/aweme/v1/web/aweme/detail/?'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user