Skip to main content

A powerful crawler for Wallhaven website

Project description

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。


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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wallhaven_crawler-0.1.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wallhaven_crawler-0.1.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file wallhaven_crawler-0.1.2.tar.gz.

File metadata

  • Download URL: wallhaven_crawler-0.1.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.6

File hashes

Hashes for wallhaven_crawler-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6544414f17b28535390633bab69cf0c7b9a1f566893c895a37dccbde5465ae49
MD5 86e32d52f35ac1e84ca33835682c1705
BLAKE2b-256 9b0df0e79eef7def4151df8dae447b280a188bb5a7e93c6984999e75a024b0fb

See more details on using hashes here.

File details

Details for the file wallhaven_crawler-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for wallhaven_crawler-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 88ff5291abe1eddcfe0def4dee1c56ecf79dc13d775ba752147d5a8b7480a7fc
MD5 a2271f44865015922a1dbd272159e698
BLAKE2b-256 a259fef47d036145f1be578ac1510ca4a9cd78a39e84a5b5dd47e4149baf430f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page