11# rule34scraper
22
3- A fast Python API wrapper for booru-style image boards using selectolax (Lexbor engine).
3+ A high-performance Python API wrapper for ** Rule34.xxx ** (and other booru-style image boards). Built for speed and reliability, it uses ` selectolax ` (Lexbor engine) for lightning-fast parsing and ` httpx ` for both synchronous and asynchronous requests .
44
55## Installation
66
@@ -10,90 +10,96 @@ pip install rule34scraper
1010
1111## Usage
1212
13- ### Basic Usage
13+ ### Basic Searching
14+
15+ Returns a list of ` Post ` objects from a search result page.
1416
1517``` python
1618from rule34scraper import R34Client
1719
1820with R34Client() as client:
19- # Search posts by tags
20- posts, tags = client.get_posts(tags = " landscape" , page = 1 )
21+ # Search posts by tags (landscape, highres)
22+ posts, tags = client.get_posts(tags = " landscape highres " , page = 1 )
2123
2224 for post in posts:
23- print (f " ID: { post.id} , Score: { post.score} , Rating: { post.rating} " )
24-
25- # Get post details
26- details = client.get_post_details(posts[0 ].id)
27- print (f " Image: { details.image_url} " )
28- print (f " Size: { details.width} x { details.height} " )
29-
30- # Download image
31- client.download_post(details, directory = " downloads/" )
25+ print (f " ID: { post.id} | Score: { post.score} | Rating: { post.rating} " )
3226```
3327
34- ### Custom Base URL
28+ ### Detailed Metadata (and Creator info)
3529
36- ``` python
37- from rule34scraper import R34Client
30+ Search results provide basic info. For full metadata (including the ** creator** name, high-res URLs, and comments), use ` get_post_details ` .
3831
39- # Use a different booru site
40- client = R34Client(
41- base_url = " https://example.com/index.php" ,
42- posts_per_page = 42 ,
43- timeout = 60.0 ,
44- )
45-
46- # Custom headers
47- client = R34Client(
48- base_url = " https://example.com/index.php" ,
49- headers = {" Cookie" : " session=abc123" },
50- )
32+ ``` python
33+ with R34Client() as client:
34+ posts, _ = client.get_posts(tags = " fantasy" )
35+
36+ # Get deep details for a specific post
37+ details = client.get_post_details(posts[0 ].id)
38+
39+ print (f " Post # { details.id} | Creator: { details.creator.name} " )
40+ print (f " Full Image: { details.image_url} ( { details.width} x { details.height} ) " )
41+ print (f " Tags: { ' , ' .join([t.name for t in details.tags[:5 ]])} " )
5142```
5243
53- ### Async Client
44+ ### Async Usage
45+
46+ Ideal for high-throughput applications.
5447
5548``` python
5649import asyncio
5750from rule34scraper import AsyncR34Client
5851
5952async def main ():
6053 async with AsyncR34Client() as client:
61- posts, tags = await client.get_posts(tags = " portrait" , page = 1 )
62- details = await client.get_post_details(posts[0 ].id)
63- print (f " Image: { details.image_url} " )
54+ posts, _ = await client.get_posts(tags = " portrait" )
55+ if posts:
56+ details = await client.get_post_details(posts[0 ].id)
57+ print (f " Async Detail Result: { details.id} " )
6458
6559asyncio.run(main())
6660```
6761
68- ### User Profiles
62+ ### User Profiles & Favorites
6963
7064``` python
7165with R34Client() as client:
7266 profile = client.get_user_profile(" username" )
73- print (f " User: { profile.username} (ID: { profile.id} ) " )
74- print (f " Level: { profile.level} " )
75- print (f " Posts: { profile.post_count} " )
67+ print (f " User: { profile.username} | Level: { profile.level} " )
7668 print (f " Favorites: { profile.favorite_count} " )
69+
70+ # Access recent uploads or favorite posts
71+ for fav in profile.recent_favorites[:5 ]:
72+ print (f " Favorite Post: { fav.detail_url} " )
7773```
7874
79- ## Models
75+ ### Downloading Media
76+
77+ ``` python
78+ with R34Client() as client:
79+ details = client.get_post_details(123456 )
80+ # Automatically handles file naming and subdirectory creation
81+ filepath = client.download_post(details, directory = " my_collection" )
82+ print (f " Saved to: { filepath} " )
83+ ```
8084
81- - ` Post ` - Thumbnail entry from search results
82- - ` PostDetails ` - Full post metadata (image URL, dimensions, tags, comments)
83- - ` Tag ` - Tag with name, count, and type
84- - ` PostComment ` - User comment on a post
85- - ` UserProfile ` - User profile with stats and recent posts
85+ ## Configuration
8686
87- ## Configuration Options
87+ | Option | Type | Default | Description |
88+ | --------| ------| ---------| -------------|
89+ | ` base_url ` | ` str ` | ` https://rule34.xxx ` | Base domain for requests. |
90+ | ` timeout ` | ` float ` | ` 30.0 ` | Request timeout in seconds. |
91+ | ` posts_per_page ` | ` int ` | ` 42 ` | Default count for pagination. |
92+ | ` max_retries ` | ` int ` | ` 5 ` | Retry attempts on rate limiting. |
93+ | ` headers ` | ` dict ` | * Browser-like* | Custom User-Agent or Cookies. |
94+
95+ ## Models
8896
89- | Parameter | Type | Default | Description |
90- | -----------| ------| ---------| -------------|
91- | ` base_url ` | str | ` https://rule34.xxx/index.php ` | Base URL for the API |
92- | ` timeout ` | float | 30.0 | Request timeout in seconds |
93- | ` posts_per_page ` | int | 42 | Posts per page for pagination |
94- | ` headers ` | dict | Browser-like headers | Custom HTTP headers |
95- | ` max_retries ` | int | 5 | Max retries for rate limits (429) |
97+ - ** Post** : Basic entry from listings (id, preview_url, tags, score, rating).
98+ - ** PostDetails** : Full data from the post page (creator, image_url, sample_url, dimensions, comments).
99+ - ** Tag** : Tag entry with ` name ` , ` count ` , and ` type ` (e.g., character, artist).
100+ - ** UserProfile** : User stats, join date, and lists of recent uploads/favorites.
101+ - ** PostComment** : Comment on a post with user, text, and timestamp.
96102
97103## License
98104
99- MIT
105+ MIT - See the [ LICENSE ] ( LICENSE ) file for details.
0 commit comments