Backend Development 5 min read

Downloading Watermark‑Free Douyin Videos with Python and jsonpath

This article demonstrates a simpler method for extracting and downloading watermark‑free Douyin (TikTok) videos by inspecting network requests, locating the hidden video URLs, and using a Python script with the jsonpath library to automate the retrieval process.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Downloading Watermark‑Free Douyin Videos with Python and jsonpath

The author revisits a previous blog about constructing Douyin video URLs and presents a more straightforward approach that eliminates many analysis steps. By opening a Douyin user page, inspecting the XHR network traffic, and navigating to the preview tab, the hidden video URLs can be found under video → download_addr → url_list .

Two URLs revealed in the response correspond to the actual video files; one of them provides a watermark‑free version. The method relies on the jsonpath module to extract the play_addr field and obtain the real video URL.

Installation of the required library is simple:

<code>pip install jsonpath</code>

The core Python script performs the following actions:

<code>import requests
import json
import jsonpath

class Douyin:
    def page_num(self, max_cursor):
        random_field = '00nvcRAUjgJQBMjqpgesfdNJ72&dytk=4a01c95562f1f10264fb14086512f919'
        url = ('https://www.iesdouyin.com/web/api/v2/aweme/post/?sec_uid=MS4wLjABAAAAU7Bwg8WznVaafqWLyLUwcVUf9LgrKGYmctJ3n5SwlOA'
               '&count=21&max_cursor=' + str(max_cursor) + '&aid=1128&_signature=' + random_field)
        headers = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36'}
        response = requests.get(url, headers=headers).text
        resp = json.loads(response)
        max_cursor = resp['max_cursor']
        for data in resp['aweme_list']:
            video_title = data['desc']
            video_url = jsonpath.jsonpath(data, '$..paly_addr')
            for a in video_url:
                video_realurl = a['url_list'][1]
            video = requests.get(video_realurl, headers=headers).content
            with open('t/' + video_title, 'wb') as f:
                print('正在下载:', video_title)
                f.write(video)
        if max_cursor == 0:
            return 1
        else:
            douyin.page_num(max_cursor)

if __name__ == '__main__':
    douyin = Douyin()
    douyin.page_num(max_cursor=0)</code>

The script iteratively fetches video metadata, extracts the watermark‑free URL, downloads the video content, and saves it locally. Advantages include reduced analysis steps, no need for a WebDriver, faster execution, and direct access to watermark‑free videos. Drawbacks are the unresolved random string generation and the somewhat cumbersome manual setup.

To run the script, install the jsonpath package, ensure the target directory exists, and execute the Python file as shown above.

JsonPathWeb ScrapingVideo DownloadDouyin
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.