欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python实现抖音视频去水印

程序员文章站 2022-03-02 13:26:12
...
import re
import requests

def get_soururl(href):
    res = requests.get(href).text
    videoid = re.findall(r'video_id%3D(.*?)%', res)[0]
    videourl = 'https://aweme.snssdk.com/aweme/v1/play/?video_id={}&ratio=720p&line=0'.format(videoid)
    print('无水印链接:',videourl)
    source_url = requests.post(videourl,allow_redirects=False,headers=headers).headers['Location']
    return source_url

def download(source_url):
    content = requests.get(source_url).content
    with open('test.mp4','wb') as f:
        f.write(content)

def getchar():
    href = input('请输入视频的分享链接')  #分享-->复制链接
    return href

if __name__ == '__main__':
    headers = {
        'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Mobile Safari/537.36',
    }
    source_url = get_soururl(getchar())
    download(source_url)
相关标签: python 爬虫