Simplified Chinese | English
Xiaohongshu link extraction/work collection tool : extract account posts, collections, likes, and album work links; extract search results work links and user links; collect Xiaohongshu work information; extract Xiaohongshu work download addresses; download Xiaohongshu Book without watermark work files!
This project is completely free and open source, without any paid functions, please do not be deceived!
The development plan and progress of XHS-Downloader can be found in Projects
? Click on the image to watch the demo video
https://www.xiaohongshu.com/explore/作品ID?xsec_token=XXX
https://www.xiaohongshu.com/discovery/item/作品ID?xsec_token=XXX
https://xhslink.com/分享码
Supports inputting multiple work links at a time, using spaces to separate links; the program will automatically extract valid links without additional processing!
It is recommended to use Windows Terminal (Windows 11 default terminal) to run the program for the best display effect!
If you only need to download the work files without watermarks, it is recommended to choose program running or Docker running ; if you have other needs, it is recommended to choose source code running !
Starting from version 2.2
, if there are no abnormalities in the project function, there is no need to process cookies additionally!
Users of Mac OS, Windows 10 and above can go to Releases to download the program compressed package, unzip it, open the program folder, and double-click to run main
to use it.
Note: The Mac OS platform executable file main
may need to be started from the terminal command line; due to device limitations, the Mac OS platform executable file has not been tested and availability cannot be guaranteed!
If you use the program in this way, the default file download path is: ._internalDownload
; the configuration file path is: ._internalsettings.json
Dockerfile
to build the imagedocker pull joeanamier/xhs-downloader
command to pull the imagedocker run -it joeanamier/xhs-downloader
docker run -it joeanamier/xhs-downloader python main.py server
docker start -i 容器名称/容器ID
docker restart -i 容器名称/容器ID
Docker does not support the command line calling mode when running the project. The functions of reading the clipboard and monitoring the clipboard cannot be used. Contents can be pasted normally. If there are any abnormalities in other functions, please report back!
3.12
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
command to install the modules required by the programmain.py
to useThe project supports command line operation mode. If you want to download some pictures of graphic works, you can use this mode to set the serial number of the pictures to be downloaded!
You can use the command line to read cookies from the browser and write to the configuration file!
Command example: python .main.py --browser_cookie Chrome --update_settings
bool
type parameters support setting using true
, false
, 1
, 0
, yes
, no
, on
or off
(case-insensitive).
Start: Run command: python .main.py server
Shutdown: Press Ctrl
+ C
to shut down the server
Request interface: /xhs/
Request method: POST
Request format: JSON
Request parameters:
parameter | type | meaning | default value |
---|---|---|---|
url | str | Links to Xiaohongshu works are automatically extracted and multiple links are not supported. | none |
download | bool | Whether to download the work file; setting it to true will take more time | false |
index | list[int] | Downloading the picture file with the specified serial number is only effective for graphic works; it does not take effect when the download parameter is set to false | null |
skip | bool | Whether to skip works with download records; setting this to true will not return data for works with download records | false |
Code example:
def api_demo(): server = "http://127.0.0.1:8000/xhs/" data = { "url": "https://www.xiaohongshu.com/explore/123456789", "download": True, "index": [ 3, 6, 9, ], } response = requests.post(server, json=data) print(response.json())
If your browser has the Tampermonkey browser extension installed, you can add user scripts and experience the project features without downloading and installing!
After the script is successfully installed, open the Xiaohongshu page, view the script instructions, and follow the prompts.
Tip: Use the XHS-Downloader user script to extract work links in batches, and use the XHS-Downloader program to batch download work files without watermarks!
If you have other needs, you can call or modify the code according to the comment prompts in main.py
!
async def example(): """Set parameters through code, suitable for secondary development""" # Sample link error_link = "https://github.com/JoeanAmier/XHS_Downloader" demo_link = "https://www.xiaohongshu.com/explore/xxxxxxxxxx" multiple_links = f"{demo_link} {demo_link} {demo_link}" # Instance object work_path = "D:\" # The root path for saving work data/files, default value: project root path folder_name = "Download" # The name of the work file storage folder (automatically created), default value: Download name_format = "Work Title Work Description" user_agent = "" # User-Agent cookie = "" # Xiaohongshu web version cookie, no login required, optional parameters, login status has an impact on data collection proxy = None # Network proxy timeout = 5 # Request data timeout limit, unit: seconds, default value: 10 chunk = 1024 * 1024 * 10 # When downloading a file, the size of the data block obtained from the server each time, unit: bytes max_retry = 2 # When requesting data fails, the maximum number of retries, unit: seconds, default value: 5 record_data = False # Whether to save the work data to the file image_format = "WEBP" # Graphic and text work file download format, supports: PNG, WEBP folder_mode = False # Whether to store the files of each work in a separate folder # async with XHS() as xhs: # pass # Use default parameters async with XHS( work_path=work_path, folder_name=folder_name, name_format=name_format, user_agent=user_agent, cookie=cookie, proxy=proxy, timeout=timeout, chunk=chunk, max_retry=max_retry, record_data=record_data, image_format=image_format, folder_mode=folder_mode, ) as xhs: # Use custom parameters download = True # Whether to download the work file, default value: False # Return detailed information about the work, including download address # Return an empty dictionary when obtaining data fails print(await xhs.extract(error_link, download, )) print(await xhs.extract(demo_link, download, index=[1, 2])) # Support passing in multiple work links print(await xhs.extract(multiple_links, download, ))
The project uses pyperclip
to implement the clipboard reading function. This module will vary on different systems.
On Windows, no additional modules are required.
On Mac, this module uses the pbcopy and pbpaste commands, which should be provided with the operating system.
On Linux, this module uses the xclip or xsel commands, which should be shipped with the operating system. Otherwise, run "sudo apt-get install xclip" or "sudo apt-get install xsel" (note: xsel does not always seem to work)
On other Linux systems, you need to install the qtpy or PyQT5 module.
The settings.json
file in the project root directory is automatically generated when running for the first time, and some running parameters can be customized.
If an invalid parameter value is set, the program will use the parameter default value!
parameter | type | meaning | default value |
---|---|---|---|
work_path | str | Work data/file saving root path | Project root path |
folder_name | str | The name of the folder where the work files are stored | Download |
name_format | str | Work file name format, use spaces to separate fields. Supported fields:收藏数量 ,评论数量 ,分享数量 点赞数量 ,作品标签 ,作品ID ,作品标题 ,作品描述 ,作品类型 ,发布时间 ,最后更新时间 ,作者昵称 ,作者ID | 发布时间作者昵称作品标题 |
user_agent | str | BrowserUserAgent | Built-in Chrome User Agent |
cookies | str | Xiaohongshu web version cookie, no login required, no required parameters! | none |
proxy | str | Setup program proxy | null |
timeout | int | Request data timeout limit, unit: seconds | 10 |
chunk | int | When downloading a file, the size of the data block obtained from the server each time, unit: bytes | 2097152(2 MB) |
max_retry | int | When requesting data fails, the maximum number of retries, unit: seconds | 5 |
record_data | bool | Whether to save the work data to a file, saving format: SQLite | false |
image_format | str | Graphic and text work file download format, supports: PNG , WEBP This parameter affects the interface used when downloading images, and is not a fixed image format! | PNG |
image_download | bool | Graphic work file download switch | true |
video_download | bool | Video work file download switch | true |
live_download | bool | Graphic, text and animation file download switch | false |
folder_mode | bool | Whether to store the files of each work in a separate folder; the folder name should be consistent with the file name | false |
download_record | bool | Whether to record the ID of successfully downloaded works. If turned on, the program will automatically skip downloading works with existing records. | true |
language | str | Set the program language, currently supported: zh_CN , en_GB | zh_CN |
Other instructions: Example of obtaining the user_agent
parameter; it is strongly recommended to set it according to the actual browser information!
Starting from version 2.2
, if there are no abnormalities in the project function, there is no need to process cookies additionally!
https://www.xiaohongshu.com/explore
F12
to open developer tools网络
tab保留日志
cookie-name:web_session
in the过滤
input boxFetch/XHR
filter网络
tab (if there is no packet, repeat step 7)XHS-Downloader will store the ID of the downloaded work in the database. When downloading the same work repeatedly, XHS-Downloader will automatically skip the file download of the work (even if the work file does not exist). If you want to re-download the work file, Please delete the corresponding work ID in the database first, and then use XHS-Downloader to download the work file!
This function is enabled by default. If it is disabled, XHS-Downloader will check whether the file exists and skip the download if the file exists!
If XHS-Downloader is helpful to you, please consider giving it a star . Thank you for your support!
Alipay | |
---|---|
If you'd like, consider funding additional support for XHS-Downloader !
Note: QQ group chat is limited to discussing project usage issues. It is strictly prohibited to publish any advertisements, and it is strictly prohibited to discuss any account transactions, account traffic, traffic monetization, gray industries and other related content!
The author's other open source projects:
JetBrains supports active projects recognized by the global open source community and provides free licenses for non-commercial development.