python 调用微博API批量回复微博评论
来源:互联网 发布:淘宝无法上架宝贝 编辑:程序博客网 时间:2024/06/02 03:35
头文件
import urllib
import urllib.requestimport http.cookiejar
import urllib.parse
import sys
import re
import base64
import json
import math
print('自动评论')
access_token = '2.00787Z_EVNDC**************'
这一段迷上了python,又经常使用新浪微博,就想搞这么个东西,闹着玩的
创建APP,什么的就不说了,回调地址用下面的:
'redirect_uri'设为'https://api.weibo.com/oauth2/default.html'
access_token我是手动添加url打开获取code,通过code获取的。
某条微博的id,即下面的mymid,需要转化成id,API有介绍。
'''mid->id'''mymid = 'BrSr7g51Q'
def get_id(mid):
url_mid = 'https://api.weibo.com/2/statuses/queryid.json'
values = {'access_token':'2.00787Z_EVNDCKDafde730d76XfRlOC',
'mid':mid,
'isBase62':'1',
'type':'1'}
data = urllib.parse.urlencode(values)
data = data.encode('UTF-8')
url_t = 'https://api.weibo.com/2/statuses/queryid.json?access_token=2.00787Z_EVNDCKDafde730d76XfRlOC&mid=BrSr7g51Q&type=1&isBase62=1'
url = 'https://api.weibo.com/2/statuses/queryid.json?access_token=2.00787Z_EVNDCKDafde730d76XfRlOC&type=1&isBase62=1&mid=' + mid
html = urllib.request.urlopen(url)
id = json.loads(html.read().decode('UTF-8'))
print (id['id'])
return id['id']
回复的小函数,需要几个参数,请查阅API。
def reply(cid,id,user):
values ={'access_token':'2.00787Z_EVNDCKDafde730d76XfRlOC',
'cid':cid,
'id':id,
'comment':'你好!python %s 评论!:)' % user}
url_reply = 'https://api.weibo.com/2/comments/reply.json'
data = urllib.parse.urlencode(values)
data =data.encode('UTF-8')
url =urllib.request.Request(url_reply,data)
html = urllib.request.urlopen(url)
获取所有评论信息,利用评论获取评论者信息,信息包含reply需要的cid,id等信息。
'''通过id获取某条微博的所有评论信息'''
def show(id):
url_show = 'https://api.weibo.com/2/comments/show.json'
values = {'access_token':'2.00787Z_EVNDCKDafde730d76XfRlOC',
'id':id}
data = urllib.parse.urlencode(values)
data = data.encode('UTF-8')
url = 'https://api.weibo.com/2/comments/show.json?access_token=2.00787Z_EVNDCKDafde730d76XfRlOC&id=' + id
html = urllib.request.urlopen(url)
s = json.loads(html.read().decode('UTF-8'))
j = s['total_number']
for i in range(0,j):
print(i)
cid = s['comments'][i]['mid']
print(cid)
user = s['comments'][i]['user']['screen_name']
reply(cid,id,user)
show(get_id(mymid))
大功告成,花了好几天,从不懂到这么个东西,浪费了很多重要时间。解释就不这么详细了。转载请注明来源!!!!
0 0
- python 调用微博API批量回复微博评论
- Python调用微博API
- python调用新浪微博API
- Python调用微博api实践
- Python调用微博API获取微博内容
- 如何通过python调用新浪微博的API
- 使用python调用新浪微博API的小经历
- 如何通过python调用新浪微博的API
- Python批量删除微博
- 微博订阅评论
- python抓取新浪微博评论并分析
- Python包装网页微信API并实现简单自动回复
- 微博评论的设计
- Android编写微博评论
- 数据库 评论和评论回复
- python模拟登录新浪微博自动获得调用新浪api所需的code
- python模拟登录新浪微博自动获得调用新浪api所需的code
- python itchat实现微信自动回复
- 移动端手机网站限制input只能输入数字
- Android_联系人PinnedHeaderListView使用
- Python 申请license写入etc/rc.local
- bzoj 3709 [PA2014]Bohater(贪心)
- iOS- CoreData 数据库管理利器!
- python 调用微博API批量回复微博评论
- 代码保存、配色、发布-整体方案----一段代码的配色
- 旋转角度计算(旋转手势)
- ios Image裁剪成圆形的方法
- Apache,Tomcat集群和负载均衡 教程
- oracle 时间函数(sysdate)
- 反思
- 11 得分排序
- 模板在三层架构上的应用