根据dy分享链接获取无水印视频
需要python3环境,实现方式如下代码[Python] 纯文本查看 复制代码 import re,requests,json
# videourl = "https://v.douyin.com/NFFy7TG/"
videourl = input("输入抖音分享链接:")
headers = {
'user-agent' : 'Android',
}
# 获取解析后url,提取视频ID
videonum = requests.get(url=videourl,headers=headers)
res = re.findall('video/(\d+)/',videonum.url)
# 获取视频json详细信息
api = f"https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={res[0]}"
js = json.loads(requests.get(api,headers=headers).text)
# 获取带有水印的视频地址
vurl = js['item_list'][0]['video']['play_addr']['url_list'][0]
# 将playwm替换成play
vvurl=re.sub(r'playwm','play',vurl)
# 获取视频二进制内容并写入到文件保存
text = requests.get(vvurl,headers=headers).content
# 此步骤可以自己提取视频ID当做视频名字,我这里直接写死了
location='D:/douyin/Video.mp4'
# 写入到mp4文件
with open(location,'ab') as fo:
fo.write(text)
fo.flush()
print("下载完成保存到D盘下的douyin文件夹")
fo.close
萌新练手,给有需要的同学~ |