首页 > 代码库 > Python 获取新浪微博的热门话题 (API)
Python 获取新浪微博的热门话题 (API)
#!/usr/bin/python
# -*- coding: utf-8 -*-
‘‘‘
Created on 2014-06-27
@author: guaguastd
# sina weibo basic secret information
APP_KEY = ‘‘ # app key
APP_SECRET = ‘‘ # app secret
REDIRECT_URL = ‘‘
USER_NAME = ‘‘
USER_PASSWD = ‘‘
# get weibo_api to access sina api
weibo_api = weibo_login(APP_KEY=APP_KEY, APP_SECRET=APP_SECRET, REDIRECT_URL=REDIRECT_URL, USER_NAME=USER_NAME, USER_PASSWD=USER_PASSWD)
# get trends by hourly, by daily, by weekly
while 1:
choice = int(raw_input("\ninput choice to get trends (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):"))
if choice == 0:
break
elif choice == 1:
print ‘Hourly trends are as follow:\r‘
hourly_trends = weibo_api.trends.hourly.get()
print json.dumps(hourly_trends, indent=1)
elif choice == 2:
print ‘Daily trends are as follow:\r‘
daily_trends = weibo_api.trends.daily.get()
print json.dumps(daily_trends, indent=1)
elif choice == 3:
print ‘Weekly trends are as follow:\r‘
weekly_trends = weibo_api.trends.weekly.get()
print json.dumps(weekly_trends, indent=1)
# -*- coding: utf-8 -*-
‘‘‘
Created on 2014-06-27
@author: guaguastd
‘‘‘
import json# Refer to http://blog.csdn.net/guaguastd/article/details/33664443
from login import weibo_login
# sina weibo basic secret information
APP_KEY = ‘‘ # app key
APP_SECRET = ‘‘ # app secret
REDIRECT_URL = ‘‘
USER_NAME = ‘‘
USER_PASSWD = ‘‘
# get weibo_api to access sina api
weibo_api = weibo_login(APP_KEY=APP_KEY, APP_SECRET=APP_SECRET, REDIRECT_URL=REDIRECT_URL, USER_NAME=USER_NAME, USER_PASSWD=USER_PASSWD)
# get trends by hourly, by daily, by weekly
while 1:
choice = int(raw_input("\ninput choice to get trends (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):"))
if choice == 0:
break
elif choice == 1:
print ‘Hourly trends are as follow:\r‘
hourly_trends = weibo_api.trends.hourly.get()
print json.dumps(hourly_trends, indent=1)
elif choice == 2:
print ‘Daily trends are as follow:\r‘
daily_trends = weibo_api.trends.daily.get()
print json.dumps(daily_trends, indent=1)
elif choice == 3:
print ‘Weekly trends are as follow:\r‘
weekly_trends = weibo_api.trends.weekly.get()
print json.dumps(weekly_trends, indent=1)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。