mirror of
https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
synced 2025-04-21 09:50:14 +08:00
🗳修复TikTok部分短链接解析失败的问题
This commit is contained in:
parent
f3e7406c7d
commit
2ca727cb02
@ -20,6 +20,7 @@ class Scraper:
|
|||||||
Scraper.douyin():抖音视频/图集解析,返回字典。
|
Scraper.douyin():抖音视频/图集解析,返回字典。
|
||||||
Scraper.tiktok():TikTok视频解析,返回字典。
|
Scraper.tiktok():TikTok视频解析,返回字典。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.headers = {
|
self.headers = {
|
||||||
'user-agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36 Edg/87.0.664.66'
|
'user-agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36 Edg/87.0.664.66'
|
||||||
@ -248,6 +249,7 @@ class Scraper:
|
|||||||
# 从请求头中获取原始链接
|
# 从请求头中获取原始链接
|
||||||
response = requests.get(url=original_url, headers=headers, allow_redirects=False)
|
response = requests.get(url=original_url, headers=headers, allow_redirects=False)
|
||||||
true_link = response.headers['Location'].split("?")[0]
|
true_link = response.headers['Location'].split("?")[0]
|
||||||
|
original_url = true_link
|
||||||
# TikTok请求头返回的第二种链接类型
|
# TikTok请求头返回的第二种链接类型
|
||||||
if '.html' in true_link:
|
if '.html' in true_link:
|
||||||
response = requests.get(url=true_link, headers=headers, allow_redirects=False)
|
response = requests.get(url=true_link, headers=headers, allow_redirects=False)
|
||||||
@ -379,7 +381,7 @@ class Scraper:
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# 测试类
|
# 测试类
|
||||||
scraper = Scraper()
|
scraper = Scraper()
|
||||||
tiktok_url = "https://www.tiktok.com/@oregonzoo/video/7074995215647477034"
|
tiktok_url = "https://vm.tiktok.com/TTPdHbphWF/"
|
||||||
tiktok_date = scraper.tiktok(tiktok_url)
|
tiktok_date = scraper.tiktok(tiktok_url)
|
||||||
print(tiktok_date)
|
print(tiktok_date)
|
||||||
print('')
|
print('')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user