Python SDK安装步骤,请参考我的上一篇文章:微博Python SDK 发微博
1. 爬取微博及对应的评论
微博接口为:statuses/user_timeline
评论接口为:comments/show
from weibo import APIClient
APP_KEY = '1234567' # app key
APP_SECRET = 'abcdefghijklmn' # app secret
CALLBACK_URL = 'http://www.example.com/callback' # callback url
client = APIClient(APP_KEY, APP_SECRET, CALLBACK_URL)
# url = client.get_authorize_url() #获取授权连接,在浏览器打开,授权后获取access_token
# print url
code = '1abaef932e70b460a48f4b5c87c5bd9d' #access_token
r = client.request_access_token(code)
#print r
access_token = r.access_token
expires_in = r.expires_in
client.set_access_token(access_token, expires_in)
print '-----------------statuses/user_timeline start------------------'
status

本文介绍了如何使用Python SDK来爬取微博及其评论。详细步骤包括安装SDK、调用statuses/user_timeline接口获取微博,使用comments/show接口抓取评论,以及通过account/get_uid和users/show接口获取用户信息。
最低0.47元/天 解锁文章
554

被折叠的 条评论
为什么被折叠?



