Skip to main content

A professional Weibo crawler library

Project description

Crawl4Weibo

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

特性

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

安装

pip install crawl4weibo

快速开始

from crawl4weibo import WeiboClient

# 初始化(无需Cookie)
client = WeiboClient()
test_uid = "2656274875"

# 获取用户信息
user = client.get_user_by_uid(test_uid)
print(f"用户名: {user.screen_name}")
print(f"粉丝数: {user.followers_count}")
print(f"微博数: {user.posts_count}")

# 获取微博
posts_page1 = client.get_user_posts(test_uid, page=1)
posts_page2 = client.get_user_posts(test_uid, page=2)
posts = (posts_page1 or []) + (posts_page2 or [])
print(f"获取到 {len(posts)} 条微博")
for i, post in enumerate(posts[:3], 1):
    print(f"  {i}. {post.text[:50]}...")
    print(f"     点赞: {post.attitudes_count} | 评论: {post.comments_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} (粉丝: {user.followers_count})")
        
# 搜索微博
posts = client.search_posts("人工智能", page=1)
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


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.3.tar.gz (100.1 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.3-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for crawl4weibo-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3945d14d25cfc5f96cbd9d1b874f552b4a896c0cf1b8d1c5eec1a14da915e30b
MD5 cb4383819395601da8217b9be13887a7
BLAKE2b-256 5230a9765606af1ce15242928c5dc9a5aeed744ccb9f50be39c6f0e0357b7524

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for crawl4weibo-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 259252d45c4afcd554489655ad4b38926d0e73d9a008e377946555ec29c74f9d
MD5 cf185ea6489ab6c6c48618411d8c0aa7
BLAKE2b-256 3d2220f4711617920b70e9783e7e3c9a38275f7682dffb40a94f4b25ef4acbc8

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