Skip to main content

A professional Weibo crawler library

Project description

Crawl4Weibo

一个专业的微博爬虫Python库,基于实际测试成功的方案,无需Cookie即可使用。

特性

  • 🚀 开箱即用: 无需Cookie,一行代码初始化
  • 🛡️ 防反爬: 自动处理432错误和请求限制
  • 📱 真实模拟: 使用真实手机浏览器UA
  • 🔄 智能重试: 自动重试机制
  • 📊 结构化数据: 清晰的数据模型

安装

pip install -e .

快速开始

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}")

# 搜索用户
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) - 获取用户微博
  • search_users(query, page=1, count=10) - 搜索用户
  • search_posts(query, page=1) - 搜索微博

数据模型

User (用户):

  • screen_name - 用户名
  • followers_count - 粉丝数
  • posts_count - 微博数
  • verified - 是否认证

Post (微博):

  • text - 微博文本
  • attitudes_count - 点赞数
  • comments_count - 评论数
  • created_at - 发布时间

运行示例

python examples/simple_example.py

技术实现

基于你提供的成功代码实现:

# 核心技术栈
- Android Chrome UA模拟
- 移动端API接口
- 自动session管理  
- 432错误智能重试
- 随机请求间隔

许可证

MIT License

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

crawl4weibo-0.1.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

crawl4weibo-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file crawl4weibo-0.1.0.tar.gz.

File metadata

  • Download URL: crawl4weibo-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for crawl4weibo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f875f0c1429a5739408bc750256321570d449881fe52a1bd79b01d9c716b03c2
MD5 706777d3a34f9ba997792ef19cc56e7c
BLAKE2b-256 99072efce216defcc34dc5ed28fd33893c9ac5361283f5e06be61f50023320a4

See more details on using hashes here.

File details

Details for the file crawl4weibo-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for crawl4weibo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7d8cc7e57ae00bfebf205ad2f27faed20c466693ad1b4add9050f14f76ec479
MD5 6b686896beb9c7bc5bfeafdc320c3252
BLAKE2b-256 2393f51a4b665e2218258cf0ab972e50fe86fb5ec3489a886dfc05c1d8b4e682

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