Python3 获取抖音无水印视频 2020年12月23日----lanyi原创

import requests
import re
import json


def get_Douyin_Code():

print('lanyi原创--博客地址:https://www.cnblogs.com/laod') share
= input("请输入你要去水印的抖音短视频链接:") # share = "https://v.douyin.com/Jb4BLU9/" pat = '(https://v.douyin.com/.*?/)' url = re.compile(pat).findall(share)[0] # 正则匹配分享链接 print(url) rsp = requests.get (url, headers=headers, allow_redirects=False) get_douyin_code = rsp.headers['location'] get_douyin_code = re.findall(r'[0-9][0-9][0-9]*', get_douyin_code) Douyin_Code = (get_douyin_code[0]) print("抖音码:", Douyin_Code) return Douyin_Code def get_DouyinURL(): Douyin_Code = get_Douyin_Code () api_url = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=" + Douyin_Code res = requests.get(api_url, headers=headers, allow_redirects=False) rsp = json.loads(res.text) douyin_URL = (rsp["item_list"][0]['video']['play_addr']['url_list'][0]) douyin_Title = (rsp["item_list"][0]['share_info']['share_title']) douyin_URL = douyin_URL.replace('playwm', 'play') print("抖音链接:", douyin_URL) print("抖音文案:", douyin_Title) video = requests.get(url=douyin_URL, headers=headers_mobile) with open(douyin_Title + ".mp4", 'wb')as file: file.write(video.content) file.close() print("===>视频下载完成!") if __name__ == '__main__': headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3904.108 Safari/537.36'} headers_mobile = {'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'} try: get_DouyinURL () except Exception as e: print("请检查链接时否正确:", e)

 

posted @ 2020-12-23 10:56  阿久丶xin  阅读(529)  评论(0编辑  收藏  举报
Live2D