A professional Weibo crawler library
Project description
Crawl4Weibo
一个开箱即用的微博爬虫Python库,基于实际测试成功的方案,无需Cookie即可使用。
特性
- 🚀 开箱即用: 无需Cookie,一行代码初始化
- 🛡️ 防反爬: 自动处理432错误和请求限制
- 📱 真实模拟: 使用真实手机浏览器UA
- 🔄 智能重试: 自动重试机制
- 📊 结构化数据: 清晰的数据模型
安装
pip install crawl4weibo
快速开始
from crawl4weibo import WeiboClient
# 初始化(无需Cookie)
client = WeiboClient()
# 获取用户信息
user = client.get_user_by_uid("1195230310")
print(f"用户: {user.screen_name}")
print(f"粉丝: {user.followers_count:,}")
# 获取微博
posts = client.get_user_posts("1195230310")
for post in posts:
print(f"微博: {post.text[:50]}...")
print(f"点赞: {post.attitudes_count}")
# 根据微博ID获取单条微博
post = client.get_post_by_bid("Q6FyDtbQc")
print(f"微博内容: {post.text[:50]}")
# print(f"发布时间: {post.created_at}")
# print(f"图片数量: {len(post.pic_urls)}")
# 搜索用户
users = client.search_users("技术博主")
for user in users:
print(f"用户: {user.screen_name}")
# 搜索微博
posts = client.search_posts("人工智能")
for post in posts:
print(f"内容: {post.text[:50]}...")
API参考
WeiboClient
初始化
WeiboClient(cookies=None, log_level="INFO", log_file=None)
主要方法
get_user_by_uid(uid)- 获取用户信息get_user_posts(uid, page=1)- 获取用户微博get_post_by_bid(bid)- 根据微博ID获取单条微博search_users(query, page=1, count=10)- 搜索用户search_posts(query, page=1)- 搜索微博
运行示例
python examples/simple_example.py
技术实现
基于你提供的成功代码实现:
# 核心技术栈
- Android Chrome UA模拟
- 移动端API接口
- 自动session管理
- 432错误智能重试
- 随机请求间隔
许可证
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
crawl4weibo-0.1.2.tar.gz
(99.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crawl4weibo-0.1.2.tar.gz.
File metadata
- Download URL: crawl4weibo-0.1.2.tar.gz
- Upload date:
- Size: 99.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e406d80d9b0b91a72fe1d739ccc76eb4a600c7fd684faa9114bb94daeab62b6d
|
|
| MD5 |
862cc0ae670ab9ab6ad6398a297858bb
|
|
| BLAKE2b-256 |
d567b58e24a3bb328420ffa0e5ac87760ca820ad738392523fd8f9df05e04500
|
File details
Details for the file crawl4weibo-0.1.2-py3-none-any.whl.
File metadata
- Download URL: crawl4weibo-0.1.2-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
880c74c90f994cb86963c6dca9972fa8fd97f7b256cc0be3b9a76654feed3926
|
|
| MD5 |
93270c6d49206903945d730d3f4d22b0
|
|
| BLAKE2b-256 |
b3ec230392476361c8821994cdf3934105b66d9eb0da3f0fea889a53b9b18589
|