Backend Development 6 min read

Downloading Bilibili Videos with Python: A Step‑by‑Step Guide Using Fiddler and Requests

This tutorial explains how to capture Bilibili video streams with Fiddler, extract the necessary request headers and URLs, and use a concise Python script based on the requests library to download videos, handling header nuances and batch‑fetching video lists from an uploader’s page.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Downloading Bilibili Videos with Python: A Step‑by‑Step Guide Using Fiddler and Requests

The author wanted to download videos from Bilibili and, after guidance from a mentor, used Fiddler to capture the network traffic of a specific video page, identifying the video stream packet.

By inspecting the captured GET request, the URL and headers required for downloading the FLV video are revealed; the author then demonstrates a minimal Python script that uses requests.get() to fetch the video content and write it to a local file.

Example code:

<code>#######################################################################
import requests

with open("D:\video\bilibili.mp4", "wb") as f:
    f.write(requests.get(url, headers=headers, verify=False).content)  # verify=False skips SSL verification
    print("下载完成")  # core part only; fill in actual url and headers
# Note: prepend Host to the URL, e.g., http://<host>/upgcx....
#######################################################################</code>

The script works, but some videos may only download partially because the captured headers contain a Range parameter; removing this parameter allows full download. The essential headers reduce to two fields: the host (extracted from the URL) and the video identifier.

To obtain the full video URL, the author searches the page source for encrypted parameters such as hfa and hfb . These values appear in the HTML source and can be located with Fiddler’s search function.

Next, the tutorial shows how to retrieve a list of all videos from an uploader’s homepage. By clicking the “more” button, a JSON response containing video IDs and titles is captured. This JSON can be fetched with a simple GET request (cookies are not required) and parsed to enumerate videos.

The author notes that pagination was not implemented in the example; the script simply requests the first 100 videos, and adding pagination logic is straightforward.

Web ScrapingBilibiliRequestsVideo DownloadFiddler
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.