Skip to main content

Wallhaven 爬虫库使用教程

简介

Wallhaven Crawler 是一个功能强大的 Python 库,专为爬取 Wallhaven 网站上的高质量壁纸而设计。通过简单的配置,你可以轻松下载各种分类的壁纸,并自定义保存位置。

Wallhaven 网站截图

特点

  • 🚀 高效并行下载:利用多线程技术,大幅提升下载速度
  • 🔐 支持登录:可访问需要账号的 NSFW 内容
  • 🔄 智能分页:自动处理分页,无需手动干预
  • 📂 自定义保存:灵活设置图片保存位置
  • 🔍 精准爬取:支持按分类、标签、排序方式等筛选壁纸

安装方法

pip install wallhaven-crawler

基本使用

基本教程案例

1.找到你想要下载的壁纸的网址

图片描述

https://wallhaven.cc/search?categories=010&purity=100&sorting=relevance&order=desc&ai_art_filter=1

2.找到你想要保存的路径

3.设置你想下载的最大页数和最大图片数 max_pages=10, max_images=100

4.运行代码

from wallhaven_crawler import PowerfulCrawler

# 初始化爬虫(带登录信息)
crawler = PowerfulCrawler(
    #你想下载的网址
    base_url="https://wallhaven.cc/search?categories=010&purity=100&sorting=relevance&order=desc&ai_art_filter=1",
    #你保存壁纸的路径
    save_dir="E:\wallhaven-crawler\images",
    #需要下载NSFW 内容才在需要填写下面“username”,“password”,否则不需要填写
    username="你的用户名",
    password="你的密码"
)
# 开始爬取
crawler.start(max_pages=10, max_images=5)

5.完成效果

高级配置

URL 参数说明

Wallhaven 的搜索 URL 可以包含多种参数,以下是常用参数的说明:

参数 说明 示例值
categories 壁纸分类 (General/Anime/People) 111 = 全部, 100 = 仅General
purity 内容分级 (SFW/Sketchy/NSFW) 100 = 仅SFW, 111 = 全部
sorting 排序方式 date_added, relevance, random, views, favorites, toplist
order 排序顺序 desc, asc
q 搜索关键词 nature, anime, cyberpunk
ai_art_filter AI生成内容过滤 0 = 显示AI内容, 1 = 过滤AI内容

完整示例

from wallhaven_crawler import PowerfulCrawler

# 搜索带有"cyberpunk"标签的动漫壁纸,按热度排序
crawler = PowerfulCrawler(
    base_url="https://wallhaven.cc/search?q=cyberpunk&categories=010&purity=100&sorting=toplist&order=desc",
    save_dir="赛博朋克壁纸",
    max_workers=15  # 增加并行下载线程数
)

# 限制下载数量
crawler.start(max_pages=20, max_images=200)

常见问题

Q: 为什么有些壁纸无法下载?

A: 部分壁纸可能需要登录才能访问,特别是NSFW内容。请确保提供了正确的账号密码。

Q: 下载速度很慢怎么办?

A: 可以尝试增加 max_workers 参数值来提高并行下载数量,但请注意不要设置过高以避免被网站封禁。

Q: 如何只下载特定分辨率的壁纸?

A: 可以在URL中添加 resolutions=1920x1080 参数来筛选特定分辨率的壁纸。

注意事项

  • 请遵守 Wallhaven 的使用条款和版权规定
  • 避免过于频繁的请求,以防IP被临时封禁
  • 下载的图片仅供个人使用,请勿用于商业目的

贡献与反馈

如果你发现任何问题或有改进建议,欢迎提交 Issue 或 Pull Request。


本库仅用于学习和个人使用,请尊重网站规则和内容版权。

Metadata

Release files for wallhaven-crawler 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wallhaven-crawler 0.1.2
File Size Uploaded Provenance Actions
wallhaven_crawler-0.1.2.tar.gz 6.9 kB Without provenance Details for wallhaven_crawler-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wallhaven-crawler 0.1.2
File Interpreter ABI Platform Actions
wallhaven_crawler-0.1.2-py3-none-any.whl Python 3 none any Details for wallhaven_crawler-0.1.2-py3-none-any.whl

Total release size: 14.2 kB

Release files / wallhaven_crawler-0.1.2.tar.gz

Download URL wallhaven_crawler-0.1.2.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6544414f17b28535390633bab69cf0c7b9a1f566893c895a37dccbde5465ae49
BLAKE2b-256 checksum
How to use checksums
9b0df0e79eef7def4151df8dae447b280a188bb5a7e93c6984999e75a024b0fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.6

Release files / wallhaven_crawler-0.1.2-py3-none-any.whl

Download URL wallhaven_crawler-0.1.2-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88ff5291abe1eddcfe0def4dee1c56ecf79dc13d775ba752147d5a8b7480a7fc
BLAKE2b-256 checksum
How to use checksums
a259fef47d036145f1be578ac1510ca4a9cd78a39e84a5b5dd47e4149baf430f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.6

Security for wallhaven-crawler 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page