教你用Python下載抖音無水印視頻
一、獲取抖音視頻連接

得到如下信息: “5.1 HV:/ 守門員戴手套沒法系鞋帶這種體育精神,值得尊敬%遇見足球 %足球 %精彩進(jìn)球 %意甲 %唯有足球不 https://v.douyin.com/eDFd28P/ 復(fù)制此鏈接,打開Dou音搜索,直接觀看視頻!”
通過正則取到信息中的地址:
share_url='5.1 HV:/ 守門員戴手套沒法系鞋帶這種體育精神,值得尊敬%遇見足球 %足球 %精彩進(jìn)球 %意甲 %唯有足球不 https://v.douyin.com/eDFd28P/ 復(fù)制此鏈接,打開Dou音搜索,直接觀看視頻!'
short_url = re.findall('(https?://[^\s]+)', share_url)[0]
二、訪問地址對返回的數(shù)據(jù)進(jìn)行分析
通過訪問得到的短連接,請求的地址會(huì)變成下面的

然后分析返回的數(shù)據(jù):

對返回的數(shù)據(jù)逐個(gè)篩選,發(fā)現(xiàn)這個(gè)連接可以直接訪問到視頻
對請求的地址重新整理獲取源視頻的地址:
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36",
}
# 通過分享連接獲取跳轉(zhuǎn)的地址
url = requests.get(url=short_url,headers=headers).url
# 通過跳轉(zhuǎn)的地址找到item_id
item_id = re.findall('https://www.iesdouyin.com/share/video/(\d+)',url)[0]
# 請求地址獲取數(shù)據(jù)
rel_url = requests.get(url="https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+item_id,headers=headers).text
# 篩出視頻地址
video_rul = json.loads(rel_url)['item_list'][0]['video']['play_addr']['url_list'][0]
三、如何去除水印
以上步驟中可以得到視頻的地址:https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0300fg10000c29ouk4guk3mmkooa0r0&ratio=720p&line=0將其中的playwm替換為play就可以得到?jīng)]有水印的地址
video_rul = json.loads(rel_url)['item_list'][0]['video']['play_addr']['url_list'][0].replace('/playwm/', '/play/')
四、整合代碼
import requests
import re
import json
down_load_path = 'E:\下載的MP4\\'
class D_y():
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36",
}
def __init__(self,share_url):
self.share_url = share_url
def get_rel_url(self):
# short_url = re.findall('(https?://[^\s]+)', self.share_url)[0]
short_url = re.findall('(http[|s]?://[^\s]*/)', self.share_url)[0]
url = requests.get(url=short_url, headers=self.headers).url
# item_id = re.findall('https://www.iesdouyin.com/share/video/(\d+)', url)[0]
item_id = url.split('/')[5]
rel_url = requests.get(url="https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=" + item_id,headers=self.headers).text
video_rul = json.loads(rel_url)['item_list'][0]['video']['play_addr']['url_list'][0].replace('/playwm/','/play/')
video = requests.get(url=video_rul,headers=self.headers).content
video_name = json.loads(rel_url)['item_list'][0]['share_info']['share_title'].split('#')[0].split('@')[0].replace(' ','')
with open(down_load_path+str(video_name)+'.mp4','wb') as f:
f.write(video)
f.close()
print("【抖音短視頻】: {}.mp4 無水印視頻下載完成!".format(video_name))
if __name__ == '__main__':
a = input("url:")
D_y(a).get_rel_url()


大功告成?。?!
到此這篇關(guān)于教你用Python下載抖音無水印視頻的文章就介紹到這了,更多相關(guān)Python下載抖音視頻內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python使用Pycharm創(chuàng)建一個(gè)Django項(xiàng)目
這篇文章主要介紹了python使用Pycharm創(chuàng)建一個(gè)Django項(xiàng)目,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03
用Python實(shí)現(xiàn)zip密碼破解實(shí)例
大家好,本篇文章主要講的是用Python實(shí)現(xiàn)zip密碼破解實(shí)例,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下2022-01-01
Python Pandas分組聚合的實(shí)現(xiàn)方法
這篇文章主要介紹了Python Pandas分組聚合的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
PyTorch 中的傅里葉卷積實(shí)現(xiàn)示例
這篇文章主要介紹了PyTorch 中的傅里葉卷積實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
jupyter notebook遠(yuǎn)程訪問不了的問題解決方法
這篇文章主要介紹了jupyter notebook遠(yuǎn)程訪問不了的問題解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
python如何實(shí)現(xiàn)單向鏈表及單向鏈表的反轉(zhuǎn)
這篇文章主要介紹了python如何實(shí)現(xiàn)單向鏈表及單向鏈表的反轉(zhuǎn),幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下2021-03-03
如何將Pycharm中Terminal使用Powershell作為終端
這篇文章主要介紹了如何將Pycharm中Terminal使用Powershell作為終端問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05

