The Douyin remove watermark applet is too bad, you can only download one a day and you need to pay. Or write a good one in Python

For dads who make short Douyin videos, it is absolutely necessary to download a few videos without watermarks every day for reference.

Wechat has many small watermark removal programs like this, but you can only download one for free per day, otherwise you have to open a membership

Think of a way, why not use Python to climb it yourself?

first step

First look at the results obtained by directly accessing Douyin

Next, open the browser's developer tools and look at the address of the video. 

Next is the key point. First of all, you need to enable your browser to modify the UA, which is the "User-Agent" that crawlers often use. 

Create a folder on your computer

 

This is the path to the folder 

C:\Users\111\Music\MV

And run the following code on the command line in the root directory.

open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/star-river/Documents/MyChrome

In this way, you have successfully changed to UA.

 

Return to the developer mode of the Douyin page

It is found that the interface beginning with "?item_ids" contains the watermark-free Douyin video we want.

In this way, we also know the parameter values ​​​​of "item_ids" and "dytk".

However, the two links we get directly through browser access will not directly display the video, and need to be the same as above.

Final Python code implementation:

import requests
import json
import re

headers = {
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'cache-control': 'max-age=0',
    # 这个貌似很重要
    'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36',
}


def download(url):
    """
    下载抖音无水印视频
    """
    # 获取接口参数
    html = requests.get(url=url, headers=headers)
    title = re.findall('itemId: "(.*?)",', html.text)[0]
    dytk = re.findall('dytk: "(.*?)" }', html.text)[0]

    # 拼接接口
    url_item = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' + title + '&dytk=' + dytk

    # 获取抖音无水印视频链接
    html_item = requests.get(url=url_item, headers=headers)
    # 字符串转字典
    content = json.loads(html_item.text)

    # 视频接口
    url_video = content['item_list'][0]['video']['play_addr']['url_list'][1]
    response = requests.get(url_video, headers=headers, allow_redirects=True)

    # 获取重定向后的链接,这个也是无水印视频的下载链接,不过本次没用
    redirect = response.url
    print(redirect)

    # 视频是二进制,需要这种下载办法
    video = requests.get(url_video, headers=headers).content
    video_name = "douyin.mp4"
    with open(video_name, 'wb') as f:
        f.write(video)
        f.flush()
    print("下载完成")


if __name__ == '__main__':
    # 抖音链接
    url = 'https://v.douyin.com/XJj85H/'
    download(url)

 

Remember to take me~

Guess you like

Origin blog.csdn.net/weixin_56537764/article/details/118752155