Code:

#!/usr/bin/python
# -*- coding: utf-8 -*- '''
Created on 2014-06-27
@author: guaguastd
@name: sinaWeiboHotTrend.py
''' import json
from sinaWeiboLogin import sinaWeiboLogin # get weibo_api to access sina api
sinaWeiboApi = sinaWeiboLogin() # get sinaWeiboTrend
from sinaWeiboTrend import trendClass
trends = trendClass(sinaWeiboApi) # get sinaWeiboTrend by hourly, by daily, by weekly
while 1:
while True:
choice = raw_input("\ninput choice to get sinaWeiboTrend (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):")
if choice.isdigit():
choice = int(choice)
if choice == 0 or choice == 1 or choice == 2 or choice == 3 :
break
else:
print 'input error, should input int number among 0,1,2,3, try again!' else:
print 'input error, should input int number, please try again!' if choice == 0:
print 'Succssfully exit!\r'
break
elif choice == 1:
print 'Hourly sinaWeiboTrend are as follow:\r'
hourly_trends = trends.hourly_new_trend()
print json.dumps(hourly_trends, indent=1)
elif choice == 2:
print 'Daily sinaWeiboTrend are as follow:\r'
daily_trends = trends.daily_new_trend()
print json.dumps(daily_trends, indent=1)
elif choice == 3:
print 'Weekly sinaWeiboTrend are as follow:\r'
weekly_trends = trends.weekly_new_trend()
print json.dumps(weekly_trends, indent=1)
else:
print 'Input error, try again!\r'

RESULT:

input choice to get sinaWeiboTrend (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):1
Hourly sinaWeiboTrend are as follow:
{
"trends": {
"2014-07-06 08:16": [
{
"query": "\u6797\u5999\u53ef",
"amount": "26088",
"name": "\u6797\u5999\u53ef",
"delta": "26088"
},
{
"query": "\u8d1d\u513ffeynman",
"amount": "24442",
"name": "\u8d1d\u513ffeynman",
"delta": "24442"
},
{
"query": "\u5434\u901f\u73b2",
"amount": "22423",
"name": "\u5434\u901f\u73b2",
"delta": "22423"
},
{
"query": "\u8a00\u627f\u65ed",
"amount": "21956",
"name": "\u8a00\u627f\u65ed",
"delta": "21956"
},
{
"query": "\u5434\u5988",
"amount": "21533",
"name": "\u5434\u5988",
"delta": "21533"
},
{
"query": "\u591a\u59887788",
"amount": "21314",
"name": "\u591a\u59887788",
"delta": "21314"
},
{
"query": "\u52a0\u6cb9\u5434\u4ea6\u51e1",
"amount": "21051",
"name": "\u52a0\u6cb9\u5434\u4ea6\u51e1",
"delta": "21051"
},
{
"query": "\u5305\u5b50\u59b9",
"amount": "20939",
"name": "\u5305\u5b50\u59b9",
"delta": "20939"
},
{
"query": "\u7537\u795e\u9e7f\u6657\u91cd\u8fd4\u5feb\u672c",
"amount": "20570",
"name": "\u7537\u795e\u9e7f\u6657\u91cd\u8fd4\u5feb\u672c",
"delta": "20570"
},
{
"query": "\u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0",
"amount": "20033",
"name": "\u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0",
"delta": "20033"
}
]
},
"as_of": 1404605804
} input choice to get sinaWeiboTrend (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):2
Daily sinaWeiboTrend are as follow:
{
"trends": {
"2014-07-06 08:23": [
{
"query": "\u6797\u5999\u53ef",
"amount": "26434",
"name": "\u6797\u5999\u53ef",
"delta": "26434"
},
{
"query": "\u8d1d\u513ffeynman",
"amount": "24677",
"name": "\u8d1d\u513ffeynman",
"delta": "24677"
},
{
"query": "\u5434\u901f\u73b2",
"amount": "22716",
"name": "\u5434\u901f\u73b2",
"delta": "22716"
},
{
"query": "\u8a00\u627f\u65ed",
"amount": "22315",
"name": "\u8a00\u627f\u65ed",
"delta": "22315"
},
{
"query": "\u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0",
"amount": "22162",
"name": "\u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0",
"delta": "22162"
},
{
"query": "\u5434\u5988",
"amount": "21776",
"name": "\u5434\u5988",
"delta": "21776"
},
{
"query": "\u52a0\u6cb9\u5434\u4ea6\u51e1",
"amount": "21389",
"name": "\u52a0\u6cb9\u5434\u4ea6\u51e1",
"delta": "21389"
},
{
"query": "\u5305\u5b50\u59b9",
"amount": "21232",
"name": "\u5305\u5b50\u59b9",
"delta": "21232"
},
{
"query": "\u53e4\u4e3d\u7c73\u5a1c",
"amount": "19406",
"name": "\u53e4\u4e3d\u7c73\u5a1c",
"delta": "19406"
},
{
"query": "\u91d1\u661f",
"amount": "19130",
"name": "\u91d1\u661f",
"delta": "19130"
}
]
},
"as_of": 1404606238
} input choice to get sinaWeiboTrend (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):3
Weekly sinaWeiboTrend are as follow:
{
"trends": {
"2014-07-06 08:24": [
{
"query": "\u6797\u5999\u53ef",
"amount": "26434",
"name": "\u6797\u5999\u53ef",
"delta": "26434"
},
{
"query": "\u8d1d\u513ffeynman",
"amount": "24677",
"name": "\u8d1d\u513ffeynman",
"delta": "24677"
},
{
"query": "\u5434\u901f\u73b2",
"amount": "22716",
"name": "\u5434\u901f\u73b2",
"delta": "22716"
},
{
"query": "\u8a00\u627f\u65ed",
"amount": "22315",
"name": "\u8a00\u627f\u65ed",
"delta": "22315"
},
{
"query": "\u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0",
"amount": "22162",
"name": "\u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0",
"delta": "22162"
},
{
"query": "\u5434\u5988",
"amount": "21776",
"name": "\u5434\u5988",
"delta": "21776"
},
{
"query": "\u52a0\u6cb9\u5434\u4ea6\u51e1",
"amount": "21389",
"name": "\u52a0\u6cb9\u5434\u4ea6\u51e1",
"delta": "21389"
},
{
"query": "\u5305\u5b50\u59b9",
"amount": "21232",
"name": "\u5305\u5b50\u59b9",
"delta": "21232"
},
{
"query": "\u53e4\u4e3d\u7c73\u5a1c",
"amount": "19406",
"name": "\u53e4\u4e3d\u7c73\u5a1c",
"delta": "19406"
},
{
"query": "\u91d1\u661f",
"amount": "19130",
"name": "\u91d1\u661f",
"delta": "19130"
}
]
},
"as_of": 1404606244
} input choice to get sinaWeiboTrend (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):

Python 获取新浪微博的热门话题 (API)的更多相关文章

  1. Python3获取新浪微博内容乱码问题

    用python获取新浪微博最近发布内容的时候调用 public_timeline()函数的返回值是个jsonDict对象,首先需要将该对象通过json.dumps函数转换成字符串,然后对该字符串用GB ...

  2. 5-46 新浪微博热门话题 (30分)——unfinished HASH

    5-46 新浪微博热门话题   (30分) 新浪微博可以在发言中嵌入“话题”,即将发言中的话题文字写在一对“#”之间,就可以生成话题链接,点击链接可以看到有多少人在跟自己讨论相同或者相似的话题.新浪微 ...

  3. Python知乎热门话题爬取

    本例子是参考崔老师的Python3网络爬虫开发实战写的 看网页界面: 热门话题都在 explore-feed feed-item的div里面 源码如下: import requests from py ...

  4. 用python+selenium抓取微博24小时热门话题的前15个并保存到txt中

    抓取微博24小时热门话题的前15个,抓取的内容请保存至txt文件中,需要抓取排行.话题和阅读数 #coding=utf-8 from selenium import webdriver import ...

  5. 定向爬虫 - Python模拟新浪微博登录

    当我们试图从新浪微博抓取数据时,我们会发现网页上提示未登录,无法查看其他用户的信息. 模拟登录是定向爬虫制作中一个必须克服的问题,只有这样才能爬取到更多的内容. 实现微博登录的方法有很多,一般我们在模 ...

  6. 使用python的Flask实现一个RESTful API服务器端[翻译]

    最近这些年,REST已经成为web services和APIs的标准架构,很多APP的架构基本上是使用RESTful的形式了. 本文将会使用python的Flask框架轻松实现一个RESTful的服务 ...

  7. 使用python的Flask实现一个RESTful API服务器端

    使用python的Flask实现一个RESTful API服务器端 最近这些年,REST已经成为web services和APIs的标准架构,很多APP的架构基本上是使用RESTful的形式了. 本文 ...

  8. 用 Python 获取 B 站播放历史记录

    用 Python 获取 B 站播放历史记录 最近 B 站出了一个年度报告,统计用户一年当中在 B 站上观看视频的总时长和总个数.过去一年我居然在 B 站上看了2600+个视频,总计251个小时,居然花 ...

  9. python获取公网ip,本地ip及所在国家城市等相关信息收藏

    python获取公网ip的几种方式       from urllib2 import urlopen   my_ip = urlopen('http://ip.42.pl/raw').read() ...

随机推荐

  1. H5 canvas pc 端米字格 写字板

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. ALTER LANGUAGE - 修改一个过程语言的定义

    SYNOPSIS ALTER LANGUAGE name RENAME TO newname DESCRIPTION 描述 ALTER LANGUAGE 修改一门语言的定义. 目前唯一的功能就是重命名 ...

  3. confluence的安装

    参考链接:https://www.ilanni.com/?p=11989 一.什么是confluence confluence是一个专业的企业知识管理与协同软件,可以用于构建企业wiki.通过它可以实 ...

  4. 网络爬虫之框架(Scrapy)

    Scrapy爬虫框架 爬虫框架是实现爬虫功能的一个软件结构和功能组件集合. 爬虫框架是一个半成品,能够帮助用户实现专业网络爬虫. Scrapy爬虫框架结构:

  5. DHCP和PXE

    继续学习,Let's go!DHCP和PXE都是什么呢?如果非科班出身,可能一脸懵逼,好多东西需要去学习了,真的,继续学吧,付出不一定会有回报,不付出肯定就是等死了,呵呵! 一.DHCP 真正需要手动 ...

  6. 趣味ACM题——圣骑士的斩杀

    题目来源于山东省第七届ACM大学生程序设计竞赛(Execution of Paladin) 题目描述 鱼人是炉石里的一支强大种族,在探险者协会里,圣骑士有了一张新牌,叫亡者归来,效果是召唤本轮游戏中7 ...

  7. luogu 2-SAT 问题

    题目大意:给出n个bool变量,以及m个条件,条件为x,vx,y,vy,表示 x == vx || y == vy . 求匹配. 题解: 最近新学了一下2-SAT算法.2-SAT指有若干个bool变量 ...

  8. mysql、MariaDB的简单操作

    mysql的简单操作 一.查看数据库 SHOW DATABASES; 例如: MariaDB [(none)]> show databases; +--------------------+ | ...

  9. (蓝桥杯)2018JAVA B组 日志分析

    日志统计 小明维护着一个程序员论坛.现在他收集了一份"点赞"日志,日志共有N行.其中每一行的格式是: ts id 表示在ts时刻编号id的帖子收到一个"赞". ...

  10. js 列表几种循环的比较

    数组 遍历 普通遍历 最简单的一种,也是使用频率最高的一种. let arr = ['a', 'b', 'c', 'd', 'e'] for (let i = 0; i < arr.length ...