Skip to content

Latest commit

 

History

History
473 lines (470 loc) · 27.1 KB

README_EN.md

File metadata and controls

473 lines (470 loc) · 27.1 KB

XHS-Downloader

简体中文 | English

GitHub GitHub forks GitHub Repo stars Static Badge
Static Badge GitHub code size in bytes GitHub release (with filter) GitHub all releases

🔥 Xiaohongshu Link Extraction/Content Collection Tool:Extract account-published, favorited, and liked content links; extract search result content links and user links; collect Xiaohongshu content information; extract Xiaohongshu content download addresses; download Xiaohongshu watermark-free content files!

⭐ This project is completely free and open-source, with no paid features. Please do not be deceived!

⭐ Due to the author's limited energy, I was unable to update the English document in a timely manner, and the content may have become outdated, partial translation is machine translation, the translation result may be incorrect, Suggest referring to Chinese documentation. If you want to contribute to translation, we warmly welcome you.

📑 Project Features

    Program Features
  • ✅ Collect Xiaohongshu works information
  • ✅ Extract Xiaohongshu works download addresses
  • ✅ Download Xiaohongshu watermark-free works files
  • ✅ Download Xiaohongshu livePhoto files (non-watermark-free)
  • ✅ Automatically skip already downloaded works files
  • ✅ works file integrity handling mechanism
  • ✅ Customizable image works file download format
  • ✅ Persistently store works information to files
  • ✅ Store works files to a separate folder
  • ✅ Background clipboard monitoring for works download
  • ✅ Record downloaded works IDs
  • ✅ Support command line for downloading works files
  • ✅ Read cookies from browser
  • ✅ Customizable file name format
  • ✅ Support API call functionality
  • ✅ Support file breakpoint resume download
  • ✅ Intelligent recognition of works file types
    Script Features
  • ✅ Download Xiaohongshu watermark-free works files
  • ✅ Extract discovery page works links
  • ✅ Extract account-published works links
  • ✅ Extract account-favorited works links
  • ✅ Extract account-liked works links
  • ✅ Extract account-board works links
  • ✅ Extract search result works links
  • ✅ Extract search result user links

⭐ The development plan and progress of XHS-Downloader can be found at Projects

📸 Program Screenshots

🎥 Click the images to watch the demo video



🔗 Supported Links

  • https://www.xiaohongshu.com/explore/WorksID?xsec_token=XXX
  • https://www.xiaohongshu.com/discovery/item/WorksID?xsec_token=XXX
  • https://xhslink.com/ShareCode

  • Supports entering multiple content links at once, separated by spaces; the program will automatically extract valid links without additional processing!

🪟 About the Terminal

⭐ It is recommended to use the Windows Terminal (default terminal for Windows 11) to run the program for the best display effect!

🥣 Usage

If you only need to download watermark-free content files, it is recommended to choose Program Run; if you have other needs, it is recommended to choose Source Code Run!

Starting from version 2.2, if there are no abnormalities in project functionality, there is no need to handle cookies separately!

🖱 Program Run

Mac OS, Windows 10 and above users can go to Releases to download the program package, unzip it, open the program folder, and double-click to run main to use.

Note: The executable file main for Mac OS may need to be launched from the terminal command line; Due to device limitations, the Mac OS executable file has not been tested and its availability cannot be guaranteed!

If you use the program in this way, the default download path for files is: .\_internal\Download; the configuration file path is: .\_internal\settings.json

⌨️ Docker Run

  1. Get Image
    • Method 1: Build the image using the Dockerfile
    • Method 2: Pull the image using the command docker pull joeanamier/xhs-downloader
  2. Create Container
    • TUI Mode: docker run -it joeanamier/xhs-downloader
    • API Mode: docker run -it joeanamier/xhs-downloader python main.py server
  3. Run Container
    • Start Container: docker start -i ContainerName/ContainerID
    • Restart Container: docker restart -i ContainerName/ContainerID

When running the project via Docker, the command line call mode is not supported. The clipboard reading and clipboard monitoring functions are unavailable, but pasting content works fine. Please provide feedback if other features are not functioning properly!

⌨️ Source Code Run

  1. Install Python interpreter with version 3.12
  2. Download the latest source code of this project or the source code released in Releases to your local machine
  3. Open the terminal and switch to the root path of the project
  4. Run the command pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt to install the required modules
  5. Run main.py to use

🛠 Command Line Mode

The project supports command line mode. If you want to download specific images from a text and image work, you can use this mode to set the image sequence number you want to download!

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

The bool type parameters support setting with true, false, 1, 0, yes, no, on or off (case insensitive).



🖥 Server Mode

Start: Run the command: python .\main.py server

Stop: Press Ctrl + C to stop the server

Request endpoint: /xhs/

Request method: POST

Request format: JSON

Request parameters:

Parameter Type Description Default
url str Xiaohongshu content link, auto-extraction, does not support multiple links; Required parameter None
download bool Whether to download the content file; set to true will take more time; Optional parameter false
index list[int] Download specific image files by index, only effective for text and image works; not effective when the download parameter is set to false; Optional parameter null
cookie str Cookies used when requesting data; Optional parameter Settings Cookie Value
skip bool Whether to skip content with download records; set to true will not return content data with download records; Optional parameter 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())

📜 Others

  • Due to the date information carried in the links of Xiaohongshu works, using links obtained from previous dates may be subject to risk control. It is recommended to use the latest Xiaohongshu works links when downloading Xiaohongshu work files
  • Windows system requires running programs as an administrator to read Chromium, Chrome, Edge browser cookies
  • If the function to save works data to a file is enabled, the works data will be stored by default in the ./Download/ExploreData.db file
  • The program's download records will be stored in the ./ExploreID.db file

🕹 User Script

If your browser has the Tampermonkey browser extension installed, you can add the user script to experience the project features without needing to download or install anything!

After successfully installing the script, open the Xiaohongshu page, check the script instructions, and follow the prompts to operate.


Note: Using the XHS-Downloader user script to batch extract content links, in combination with the XHS-Downloader program, can achieve batch downloading of watermark-free content files!

📜 Script Instructions

  • When downloading watermark-free Xiaohongshu作品 files, the script will take some time to process the files, please wait a moment and do not click the download button multiple times
  • Watermark-free image files are in PNG format; watermark-free video files are larger and may take longer to process, page jumps may cause download failures
  • (Disabled)When extracting links of account posts, favorites, likes, and album作品, the script will attempt to automatically scroll the screen until all作品 are loaded, with a scroll detection interval of 2.5 seconds
  • (Disabled)When extracting discovery作品 links, search作品, and user links, the script will automatically scroll the screen to try to load more content, scrolling the screen up to 10 times
  • (Disabled)You can modify the scroll detection interval and the number of screen scrolls, changes will take effect immediately; you can also disable the automatic screen scrolling function and manually scroll to load content
  • Using global proxy tools may cause the script to fail to download files, if there are issues, please try closing the proxy tool, and feedback to the author if necessary
  • The XHS-Downloader user script only implements the data collection function that can be obtained visibly, with no paid features or cracking functions

💻 Secondary Development

If you have other needs, you can perform code calls or modifications based on the comments in main.py!

async def example():
    """通过代码设置参数,适合二次开发"""
    # 示例链接
    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}"
    # 实例对象
    work_path = "D:\\"  # 作品数据/文件保存根路径,默认值:项目根路径
    folder_name = "Download"  # 作品文件储存文件夹名称(自动创建),默认值:Download
    name_format = "作品标题 作品描述"
    user_agent = ""  # User-Agent
    cookie = ""  # 小红书网页版 Cookie,无需登录,可选参数,登录状态对数据采集有影响
    proxy = None  # 网络代理
    timeout = 5  # 请求数据超时限制,单位:秒,默认值:10
    chunk = 1024 * 1024 * 10  # 下载文件时,每次从服务器获取的数据块大小,单位:字节
    max_retry = 2  # 请求数据失败时,重试的最大次数,单位:秒,默认值:5
    record_data = False  # 是否保存作品数据至文件
    image_format = "WEBP"  # 图文作品文件下载格式,支持:PNG、WEBP
    folder_mode = False  # 是否将每个作品的文件储存至单独的文件夹
    # async with XHS() as xhs:
    #     pass  # 使用默认参数
    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:  # 使用自定义参数
        download = True  # 是否下载作品文件,默认值:False
        # 返回作品详细信息,包括下载地址
        # 获取数据失败时返回空字典
        print(await xhs.extract(error_link, download, ))
        print(await xhs.extract(demo_link, download, index=[1, 2]))
        # 支持传入多个作品链接
        print(await xhs.extract(multiple_links, download, ))

📋 Read Clipboard

The project uses pyperclip to implement clipboard reading functionality, which varies across different systems.

On Windows, no additional modules are needed.

On Mac, this module makes use of the pbcopy and pbpaste commands, which should come with the os.

On Linux, this module makes use of the xclip or xsel commands, which should come with the os. Otherwise run "sudo apt-get install xclip" or "sudo apt-get install xsel" (Note: xsel does not always seem to work.)

Otherwise on Linux, you will need the qtpy or PyQT5 modules installed.

⚙️ Configuration File

The settings.json file in the root directory of the project is automatically generated on the first run and allows customization of some runtime parameters.

If invalid parameter values are set, the program will use the default values!

Parameter Type Description Default Value
work_path str Root path for saving content data/files Project root path
folder_name str Name of the folder for storing content files Download
name_format str 1Format of works file name, separated by spaces between fields, supports fields: 收藏数量评论数量分享数量点赞数量作品标签作品ID作品标题作品描述作品类型发布时间最后更新时间作者昵称作者ID 发布时间 作者昵称 作品标题
user_agent str Browser User Agent Built-in Chrome User Agent
cookie str Xiaohongshu web version cookie, No login required, non essential parameters! None
proxy str Set program proxy null
timeout int Request data timeout limit, in seconds 10
chunk int Size of data chunk to fetch from the server each time when downloading files, in bytes 2097152(2 MB)
max_retry int Maximum number of retries when requesting data fails 5
record_data bool Whether to save content data to a file, saved in SQLite format false
image_format str Download format for text and image content files, supported formats: PNG, WEBP
This parameter affects the API used when downloading images, not the fixed image format!
PNG
image_download bool Switch for downloading text and image content files true
video_download bool Switch for downloading video content files true
live_download bool Switch for downloading animated image files false
folder_mode bool Whether to store each content's files in a separate folder; the folder name matches the file name false
download_record bool Do record the ID of successfully downloaded works? If enabled, the program will automatically skip downloading works with records true
language str Set program language. Currently supported: zh_CN, en_US zh_CN

name_format instructions (Currently only supports Chinese values) :

  • 收藏数量: Number of Collections
  • 评论数量: Number of Comments
  • 分享数量: Number of Shares
  • 点赞数量: Number of Likes
  • 作品标签: Works Tags
  • 作品ID: Works ID
  • 作品标题: Works Title
  • 作品描述: Works Description
  • 作品类型: Works Type
  • 发布时间: Publish Time
  • 最后更新时间: Last Updated Time
  • 作者昵称: Author Nickname
  • 作者ID: Author ID

Additional Notes: The parameters user_agent examples are provided for reference; Strongly recommend setting according to actual browser information!

🌐 Cookie

Starting from version 2.2, if there are no abnormalities in project functionality, there is no need to handle cookies separately!

  1. Open the browser (optional: start in incognito mode) and visit https://www.xiaohongshu.com/explore
  2. Log in to your Xiaohongshu account (can be skipped)
  3. Press F12 to open the developer tools
  4. Select the Network tab
  5. Check Preserve log
  6. In the Filter input box, enter cookie-name:web_session
  7. Select the Fetch/XHR filter
  8. Click on any piece of content on the Xiaohongshu page
  9. In the Network tab, select any data packet (if no packets appear, repeat step 7)
  10. Copy and paste the entire Cookie into the program or configuration file

🗳 Download Records

XHS-Downloader will store the IDs of downloaded content in a database. When downloading the same content again, XHS-Downloader will automatically skip the file download (even if the content file does not exist). If you want to re-download the content file, please delete the corresponding content ID from the database and then use XHS-Downloader to download the content file again!

This feature is enabled by default. If it is turned off, XHS-Downloader will check if the file exists. If the file exists, it will skip the download!

♥️ Support the Project

If XHS-Downloader has been helpful to you, please consider giving it a Star ⭐. Thank you for your support!

微信(WeChat) 支付宝(Alipay)
微信赞助二维码 支付宝赞助二维码

If you are willing, you may consider making a donation to provide additional support for XHS-Downloader!

✉️ Contact the Author

Other Open Source Projects by the Author:

💰 Sponsor

PyCharm logo

JetBrains support active projects recognized within the global open-source community with complimentary licenses for non-commercial development.

⚠️ Disclaimer

  • Users decide on their own how to use this project and bear the risks themselves. The author is not responsible for any losses, liabilities, or risks incurred by users in the use of this project
  • The code and functionalities provided by the author of this project are developed based on existing knowledge and technology. The author strives to ensure the correctness and security of the code but does not guarantee that the code is completely error-free or defect-free.
  • Users must strictly adhere to the provisions in GNU General Public License v3.0 , and appropriately mention the use of code adhering GNU General Public License v3.0.
  • Under no circumstances shall users associate the author of this project, contributors, or other related parties with the user's usage behavior, or demand that they be held responsible for any losses or damages incurred by the user's use of this project.
  • Users must independently study relevant laws and regulations when using the code and functionalities of this project and ensure that their usage is legal and compliant. Users are solely responsible for any legal liability and risks resulting from violations of laws and regulations.
  • The author of this project will not provide a paid version of the XHS-Downloader project, nor will they offer any commercial services related to the XHS-Downloader project.
  • Any secondary development, modification, or compilation of the program based on this project is unrelated to the original author. The original author is not responsible for any consequences related to secondary development or its results. Users should take full responsibility for any situations that may arise from secondary development on their own.
Before using the code and functionalities of this project, please carefully consider and accept the above disclaimer. If you have any questions or disagree with the statement, please do not use the code and functionalities of this project. If you use the code and functionalities of this project, it is considered that you fully understand and accept the above disclaimer, and willingly assume all risks and consequences associated with the use of this project.

💡 Project References