GithubHelp home page GithubHelp logo

joeanamier / xhs-downloader Goto Github PK

View Code? Open in Web Editor NEW
3.4K 17.0 485.0 5.4 MB

小红书链接提取/作品采集工具:提取账号发布、收藏、点赞作品链接;提取搜索结果作品、用户链接;采集小红书作品信息;提取小红书作品下载地址;下载小红书无水印作品文件!

License: GNU General Public License v3.0

Python 60.98% JavaScript 39.02%
python xhs json exe linux macos windows tui aiohttp textual

xhs-downloader's Introduction


XHS-Downloader

简体中文 | English

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

🔥 小红书链接提取/作品采集工具:提取账号发布、收藏、点赞作品链接;提取搜索结果作品、用户链接;采集小红书作品信息;提取小红书作品下载地址;下载小红书无水印作品文件!

📑 项目功能

    程序功能
  • ✅ 采集小红书作品信息
  • ✅ 提取小红书作品下载地址
  • ✅ 下载小红书无水印作品文件
  • ✅ 自动跳过已下载的作品文件
  • ✅ 作品文件完整性处理机制
  • ✅ 自定义图文作品文件下载格式
  • ✅ 持久化储存作品信息至文件
  • ✅ 作品文件储存至单独文件夹
  • ✅ 后台监听剪贴板下载作品
  • ✅ 记录已下载作品 ID
  • ✅ 支持命令行下载作品文件
  • ✅ 从浏览器读取 Cookie
  • ☑️ 支持 API 调用功能
    脚本功能
  • ✅ 下载小红书无水印作品文件
  • ✅ 提取发现页面作品链接
  • ✅ 提取账号发布作品链接
  • ✅ 提取账号收藏作品链接
  • ✅ 提取账号点赞作品链接
  • ✅ 提取搜索结果作品链接
  • ✅ 提取搜索结果用户链接

📸 程序截图

🎥 点击图片观看演示视频



🔗 支持链接

  • https://www.xiaohongshu.com/explore/作品ID
  • https://www.xiaohongshu.com/discovery/item/作品ID
  • https://xhslink.com/分享码

  • 支持单次输入多个作品链接,链接之间使用空格分隔。

🪟 关于终端

⭐ 推荐使用 Windows 终端 (Windows 11 默认终端)运行程序以便获得最佳显示效果!

🥣 使用方法

如果仅需下载无水印作品文件,建议选择 程序运行;如果有其他需求,建议选择 源码运行

建议自行设置 cookie 参数,若不设置该参数,程序功能可能无法正常使用!

🖱 程序运行

Windows 10 及以上用户可前往 Releases 下载程序压缩包或安装包,解压或安装后打开程序文件夹,双击运行 main.exe 即可使用。

若通过此方式使用程序,文件默认下载路径为:.\_internal\Download;配置文件路径为:.\_internal\settings.json

⌨️ 源码运行

  1. 安装版本号不低于 3.12 的 Python 解释器
  2. 运行 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt 命令安装程序所需模块
  3. 下载本项目最新的源码或 Releases 发布的源码至本地
  4. 运行 main.py 即可使用

🛠 命令行模式

项目支持命令行运行模式,若想要下载图文作品的部分图片,可以使用此模式传入需要下载的图片序号!

可以使用命令行从浏览器读取 Cookie 并写入配置文件!注意需要关闭对应浏览器才能读取数据!

bool 类型参数支持使用 truefalse10yesnoonoff(不区分大小写)来设置。

命令示例:python .\main.py --browser_cookie Chrome --update_settings



🕹 用户脚本


如果您的浏览器安装了 Tampermonkey 浏览器扩展程序,可以添加 用户脚本,无需下载安装即可体验项目功能!

提示:使用 XHS-Downloader 用户脚本批量提取作品链接,搭配 XHS-Downloader 程序可以实现批量下载无水印作品文件!

💻 二次开发

如果有其他需求,可以根据 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
    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,
                   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, ))
        # 支持传入多个作品链接
        print(await xhs.extract(multiple_links, download, ))

⚙️ 配置文件

项目根目录下的 settings.json 文件,首次运行自动生成,可以自定义部分运行参数。

参数 类型 含义 默认值
work_path str 作品数据 / 文件保存根路径 项目根路径
folder_name str 作品文件储存文件夹名称 Download
user_agent str 请求头 User-Agent 默认 UA
cookie str 小红书网页版 Cookie,无需登录
proxy str 设置程序代理 null
timeout int 请求数据超时限制,单位:秒 10
chunk int 下载文件时,每次从服务器获取的数据块大小,单位:字节 1048576(1 MB)
max_retry int 请求数据失败时,重试的最大次数,单位:秒 5
record_data bool 是否保存作品数据至文件,保存格式:SQLite false
image_format str 图文作品文件下载格式,支持:PNGWEBP PNG
image_download bool 图文作品文件下载开关 true
video_download bool 视频作品文件下载开关 true
folder_mode bool 是否将每个作品的文件储存至单独的文件夹;文件夹名称与文件名称保持一致 false
language str 设置程序语言,目前支持:zh_CNen_GB zh_CN

🌐 Cookie

  1. 打开浏览器(可选无痕模式启动),访问 https://www.xiaohongshu.com/explore
  2. 按下 F12 打开开发人员工具
  3. 选择 网络 选项卡
  4. 勾选 保留日志
  5. 过滤 输入框输入 cookie-name:web_session
  6. 选择 Fetch/XHR 筛选器
  7. 点击小红书页面任意作品
  8. 网络 选项卡选择任意数据包(如果无数据包,重复步骤7)
  9. 全选复制 Cookie 写入程序或配置文件

🗳 下载记录

XHS-Downloader 会将下载过的作品 ID 储存至数据库,当重复下载相同的作品时,XHS-Downloader 会自动跳过该作品的文件下载(即使作品文件不存在),如果想要重新下载作品文件,请先删除数据库中对应的作品 ID,再使用 XHS-Downloader 下载作品文件!

♥️ 支持项目

如果 XHS-Downloader 对您有帮助,请考虑为它点个 Star ⭐,感谢您的支持!

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

如果您愿意,可以考虑提供资助为 XHS-Downloader 提供额外的支持!

✉️ 联系作者

  • 微信(其他事务): Downloader_Tools
  • 微信公众号(问题解答): Downloader Tools
  • QQ 群聊(使用交流): 扫码加入群聊

说明:QQ 群聊仅限于讨论项目使用问题,严禁发布任何广告,严禁讨论任何账号交易、账号流量、流量变现、灰色产业等相关的内容!

作者的其他开源项目:

⚠️ 免责声明

  • 使用者对本项目的使用由使用者自行决定,并自行承担风险。作者对使用者使用本项目所产生的任何损失、责任、或风险概不负责。
  • 本项目的作者提供的代码和功能是基于现有知识和技术的开发成果。作者尽力确保代码的正确性和安全性,但不保证代码完全没有错误或缺陷。
  • 使用者在使用本项目时必须严格遵守 GNU General Public License v3.0 的要求,并在适当的地方注明使用了 GNU General Public License v3.0 的代码。
  • 使用者在任何情况下均不得将本项目的作者、贡献者或其他相关方与使用者的使用行为联系起来,或要求其对使用者使用本项目所产生的任何损失或损害负责。
  • 使用者在使用本项目的代码和功能时,必须自行研究相关法律法规,并确保其使用行为合法合规。任何因违反法律法规而导致的法律责任和风险,均由使用者自行承担。
  • 本项目的作者不会提供 XHS-Downloader 项目的付费版本,也不会提供与 XHS-Downloader 项目相关的任何商业服务。
  • 基于本项目进行的任何二次开发、修改或编译的程序与原创作者无关,原创作者不承担与二次开发行为或其结果相关的任何责任,使用者应自行对因二次开发可能带来的各种情况负全部责任。
在使用本项目的代码和功能之前,请您认真考虑并接受以上免责声明。如果您对上述声明有任何疑问或不同意,请不要使用本项目的代码和功能。如果您使用了本项目的代码和功能,则视为您已完全理解并接受上述免责声明,并自愿承担使用本项目的一切风险和后果。

💡 代码参考

xhs-downloader's People

Contributors

catdddmouse avatar chreer avatar joeanamier avatar sherlocknovitch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xhs-downloader's Issues

下载不了

如题 只是反馈
['https://sns-img-qc.xhscdn.com/1000g0082b1u344ah20005nmhkghg8cqp0mhc4k8', 'http
s://sns-img-qc.xhscdn.com/1000g0082b1u344ah200g5nmhkghg8cqps72hai8', 'https://sn
s-img-qc.xhscdn.com/1000g0082b1u344ah20105nmhkghg8cqpkauk1pg', 'https://sns-img-
qc.xhscdn.com/1000g0082b1u344ah201g5nmhkghg8cqp2s22gt0', 'https://sns-img-qc.xhs
cdn.com/1000g0082b1u344ah20205nmhkghg8cqppnekcvg', 'https://sns-img-qc.xhscdn.co
m/1000g0082b1u344ah202g5nmhkghg8cqpmui1150', 'https://sns-img-qc.xhscdn.com/1000
g0082b1u344ah20305nmhkghg8cqpft5dfcg', 'https://sns-img-qc.xhscdn.com/1000g0082b
1u344ah203g5nmhkghg8cqpcs6m5vg', 'https://sns-img-qc.xhscdn.com/1000g0082b1u344a
h20405nmhkghg8cqpffv2l28', 'https://sns-img-qc.xhscdn.com/1000g0082b1u344ah204g5
nmhkghg8cqp35u683o']

下载失败

只会自动创建文件夹,但是文件夹是空的,添加Cookie也没用

An enhancement to url handling

image

As shown in the picture, when we share a Xiaohongshu link, it may start with http.
However, the regular expression in the source code only matches https.
Can I enhance the code to automatically handle URLs starting with http to submit a pull request?

macOS 无法下载

macOS源码运行之后有一大串Traceback错误信息,最后报错
ClientConnectorCertificateError: Cannot connect to host www.xiaohongshu.com:443
ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED]
certificate verify failed: unable to get local issuer certificate
(_ssl.c:1000)')]
Exit status: 0
谢谢大大

自动化采集的设想

本地cookie能否成功获取图片与webid和websession相关

只需要可以自动的获取和运行时维护好就可以持续性的获取图片,结束的时候再保存到配置文件中即可

但是自动化采集不能采集搜索出来的web界面,没有有效的abroadID去请求列表元素,获得exporeID

quicktime format can be saved as mov format

Hello, when I was working on this link, I found a point that could improve the user experience:http://xhslink.com/6eOiVy

The video in this URL is downloaded through the program and saved in quicktime format. Its download address is https://sns-video-hw.xhscdn.com/01024301kqe0qqgvdwc050mx97r08bo2kt.

After checking the information, I learned that quicktime's default save type is mov. And when our browser (chrome and edge) opens this address, the browser will automatically save the format as mov by default.

In addition, for Windows' native video player, it usually does not support quicktime. It would be very convenient if quicktime could be saved as mov.

An idea of Web UI

I have saw another project “TikTokDownloader”,there exists a Web UI. But this "XHS-Downloader" does not have a Web UI, can I create one using “React” & “flask” and contribute my code by PR?

ClientConnectorCertificateError: Cannot connect to host www.xiaohongshu.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)')]

批量下载报错

每次批量下载几个作品后会跳出这个错误:

await waiter
aiohttp.client_exceptions.ClientPayloadError: Response payload is not completed

请问该如何解决 谢谢

如何正确反馈 EXE 程序异常闪退

如果您使用 EXE 程序发生异常闪退,请参考本教程获取程序错误代码,并将错误代码以及闪退前正在进行的操作告知作者以便查找原因!

  1. 打开资源管理器,切换至项目文件夹,右键空白区域,打开终端;或者直接在地址栏输入 cmd 后按下回车键打开终端。

PixPin_2024-01-04_19-56-15

PixPin_2024-01-04_19-58-12

  1. 在终端窗口输入 .\main.exe 或者 main.exe,按下回车键运行程序。

PixPin_2024-01-04_19-58-46

  1. 重复先前发生闪退的操作,如果程序发生异常闪退,窗口不会关闭,可以复制或者查看错误信息。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.