Python 获取新浪微博的最新公共微博

API:

statuses/public_timeline  返回最新的200条公共微博,返回结果非完全实时 

CODE:

#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Created on 2014-7-3
@author: guaguastd
@name: statuses_public_timeline.py
'''

def public_timeline(weibo_api, count):

    #public_timeline = weibo_api.statuses.public_timeline.get(count=count)
    public_timeline = weibo_api.statuses__public_timeline(count=count)
    statuses = public_timeline['statuses']
    return statuses

if __name__ == '__main__':

    # import json
    import json

    # import login, see http://blog.csdn.net/guaguastd/article/details/33664443
    from login import weibo_login

    # get the twitter access api
    weibo_api = weibo_login()

    # get the new 200 weibo
    content = public_timeline(weibo_api, 200)
    print json.dumps(content, indent=1)

RESULT:

['cc7c9d31fc797802960c84822c3654f3']
[
 {
  "reposts_count": 0,
  "truncated": false,
  "text": "\u5982\u679c\u4f60\u4e5f\u6709\u75d8\u75d8 \u75d8\u5370 \u6bdb\u5b54\u7c97\u5927 \u6697\u6c89\u6591\u70b9 \u5e72\u71e5 \u7ea2\u8840\u4e1d \u51fa\u6cb9\u9ed1\u5934 \u9ed1\u773c\u5708 \u773c\u888b \u62a4\u7406 \u51cf\u80a5 \u7b49\u7b49\u53ef\u4ee5\u52a0\u8001\u5e08QQ:1817712253\u4e00\u8d77\u5b66\u4e60",
  "visible": {
   "type": 0,
   "list_id": 0
  },
  "in_reply_to_status_id": "",
  "bmiddle_pic": "http://ww3.sinaimg.cn/bmiddle/d1a02cb3jw1ehz8g6t1m6j20c90cdq3n.jpg",
  "id": 3728143255299328,
  "thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/d1a02cb3jw1ehz8g6t1m6j20c90cdq3n.jpg",
  "mid": "3728143255299328",
  "source": "<a href=\"http://app.weibo.com/t/feed/3auC5p\" rel=\"nofollow\">\u76ae\u76ae\u65f6\u5149\u673a</a>",
  "attitudes_count": 0,
  "in_reply_to_screen_name": "",
  "pic_urls": [
   {
    "thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/d1a02cb3jw1ehz8g6t1m6j20c90cdq3n.jpg"
   }
  ],
  "in_reply_to_user_id": "",
  "darwin_tags": [],
  "favorited": false,
  "original_pic": "http://ww3.sinaimg.cn/large/d1a02cb3jw1ehz8g6t1m6j20c90cdq3n.jpg",
  "idstr": "3728143255299328",
  "user": {
   "bi_followers_count": 252,
   "domain": "",
   "avatar_large": "http://tp4.sinaimg.cn/3516935347/180/40057950890/0",
   "verified_source": "",
   "ptype": 0,
   "statuses_count": 419,
   "allow_all_comment": true,
   "id": 3516935347,
   "verified_reason_url": "",
   "city": "1",
   "province": "43",
   "block_app": 0,
   "follow_me": false,
   "verified_reason": "",
   "followers_count": 420,
   "location": "\u6e56\u5357 \u957f\u6c99",
   "verified_trade": "",
   "mbtype": 0,
   "verified_source_url": "",
   "profile_url": "u/3516935347",
   "block_word": 0,
   "avatar_hd": "http://ww3.sinaimg.cn/crop.54.22.120.120.1024/d1a02cb3gw1ehkk32gwyfj205k05k3yq.jpg",
   "star": 0,
   "description": "",
   "friends_count": 1085,
   "online_status": 0,
   "mbrank": 0,
   "allow_all_act_msg": false,
   "profile_image_url": "http://tp4.sinaimg.cn/3516935347/50/40057950890/0",
   "idstr": "3516935347",
   "verified": false,
   "geo_enabled": true,
   "class": 1,
   "screen_name": "\u8425\u517b\u7f8e\u5bb9\u8bb2\u5e08\u5c0f\u8fea",
   "lang": "zh-cn",
   "weihao": "",
   "remark": "",
   "favourites_count": 0,
   "name": "\u8425\u517b\u7f8e\u5bb9\u8bb2\u5e08\u5c0f\u8fea",
   "url": "",
   "gender": "f",
   "created_at": "Fri Jun 07 10:40:15 +0800 2013",
   "worldcup_guess": 0,
   "verified_type": -1,
   "following": false
  },
  "geo": null,
  "created_at": "Thu Jul 03 07:01:20 +0800 2014",
  "mlevel": 0,
  "comments_count": 1
 },
 {
  "reposts_count": 0,
  "truncated": false,
  "text": "\u301012\u661f\u5ea7\u8001\u516c\u7684\u4f18\u70b9\u3011\u767d\u7f8a\uff1a\u4fdd\u62a4\u4f60\u7684\u52c7\u58eb\uff1b\u91d1\u725b\uff1a\u4e0d\u6d6a\u8d39\u3001\u4e13\u4e00\uff1b\u53cc\u5b50\uff1a\u806a\u660e\u5e7d\u9ed8\uff1b\u5de8\u87f9\uff1a\u6e29\u67d4\u4f53\u8d34\uff1b\u72ee\u5b50\uff1a\u80fd\u4f9d\u9760\u7684\u5927\u6811\uff1b\u5904\u5973\uff1a\u7231\u505a\u5bb6\u52a1\uff1b\u5929\u79e4\uff1a\u813e\u6c14\u6e29\u548c\uff1b\u5929\u874e\uff1a\u5584\u89e3\u4eba\u610f\uff1b\u5c04\u624b\uff1a\u70ed\u60c5\u5927\u5ea6\uff1b\u6469\u7faf\uff1a\u8d23\u4efb\u611f\uff0c\u6301\u5bb6\uff1b\u6c34\u74f6\uff1a\u5236\u9020\u6d6a\u6f2b\uff1b\u53cc\u9c7c\uff1a\u542c\u8bdd",
  "visible": {
   "type": 0,
   "list_id": 0
  },
  "in_reply_to_status_id": "",
  "bmiddle_pic": "http://ww3.sinaimg.cn/bmiddle/005z8hcejw1ehz8g6u4jfj30f20m8mzr.jpg",
  "id": 3728143254878451,
  "thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/005z8hcejw1ehz8g6u4jfj30f20m8mzr.jpg",
  "mid": "3728143254878451",
  "source": "<a href=\"http://app.weibo.com/t/feed/3auC5p\" rel=\"nofollow\">\u76ae\u76ae\u65f6\u5149\u673a</a>",
  "attitudes_count": 0,
  "in_reply_to_screen_name": "",
  "pic_urls": [
   {
    "thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/005z8hcejw1ehz8g6u4jfj30f20m8mzr.jpg"
   }
  ],
  "in_reply_to_user_id": "",
  "darwin_tags": [],
  "favorited": false,
  "original_pic": "http://ww3.sinaimg.cn/large/005z8hcejw1ehz8g6u4jfj30f20m8mzr.jpg",
  "idstr": "3728143254878451",
  "user": {
   "bi_followers_count": 6,
   "domain": "",
   "avatar_large": "http://tp3.sinaimg.cn/5099808650/180/5693729982/0",
   "verified_source": "",
   "ptype": 0,
   "statuses_count": 838,
   "allow_all_comment": true,
   "id": 5099808650,
   "verified_reason_url": "",
   "city": "5",
   "province": "11",
   "block_app": 0,
   "follow_me": false,
   "verified_reason": "",
   "followers_count": 170,
   "location": "\u5317\u4eac \u671d\u9633\u533a",
   "verified_trade": "",
   "mbtype": 0,
   "verified_source_url": "",
   "profile_url": "u/5099808650",
   "block_word": 0,
   "avatar_hd": "http://ww3.sinaimg.cn/crop.0.0.170.170.1024/005z8hcejw1efwksyxddwj304q04qa9x.jpg",
   "star": 0,
   "description": "",
   "friends_count": 561,
   "online_status": 0,
   "mbrank": 0,
   "allow_all_act_msg": false,
   "profile_image_url": "http://tp3.sinaimg.cn/5099808650/50/5693729982/0",
   "idstr": "5099808650",
   "verified": false,
   "geo_enabled": true,
   "class": 1,
   "screen_name": "\u7231\u5c31\u4e0d\u6015\u5371\u9669",
   "lang": "zh-cn",
   "weihao": "",
   "remark": "",
   "favourites_count": 0,
   "name": "\u7231\u5c31\u4e0d\u6015\u5371\u9669",
   "url": "",
   "gender": "f",
   "created_at": "Tue Apr 29 17:10:14 +0800 2014",
   "worldcup_guess": 0,
   "verified_type": -1,
   "following": false
  },
  "geo": null,
  "created_at": "Thu Jul 03 07:01:20 +0800 2014",
  "mlevel": 0,
  "comments_count": 0
 },
 {
  "darwin_tags": [],
  "favorited": false,
  "mid": "3728143254878339",
  "in_reply_to_user_id": "",
  "truncated": false,
  "text": "\u90ed\u5fb7\u7eb2 \u4e8e\u8c26 2012\u6211\u8981\u5e78\u798f http://t.cn/z0kupX1",
  "created_at": "Thu Jul 03 07:01:20 +0800 2014",
  "mlevel": 0,
  "reposts_count": 0,
  "idstr": "3728143254878339",
  "visible": {
   "type": 0,
   "list_id": 0
  },
  "attitudes_count": 0,
  "pic_urls": [],
  "in_reply_to_screen_name": "",
  "user": {
   "bi_followers_count": 14,
   "domain": "",
   "avatar_large": "http://tp4.sinaimg.cn/5119417731/180/5696057764/1",
   "verified_source": "",
   "ptype": 0,
   "statuses_count": 144,
   "allow_all_comment": true,
   "id": 5119417731,
   "verified_reason_url": "",
   "city": "1000",
   "province": "100",
   "block_app": 0,
   "follow_me": false,
   "verified_reason": "",
   "followers_count": 137,
   "location": "\u5176\u4ed6",
   "verified_trade": "",
   "mbtype": 0,
   "verified_source_url": "",
   "profile_url": "u/5119417731",
   "block_word": 0,
   "avatar_hd": "http://ww2.sinaimg.cn/crop.0.0.120.120.1024/005AsypJjw1egrq4a029bj303c03ct8j.jpg",
   "star": 0,
   "description": "\u4e16\u754c\u4e0a\u90a3\u4e9b\u6700\u5bb9\u6613\u7684\u4e8b\u60c5\u4e2d\uff0c\u62d6\u5ef6\u65f6\u95f4\u6700\u4e0d\u8d39\u529b\u3002",
   "friends_count": 183,
   "online_status": 0,
   "mbrank": 0,
   "allow_all_act_msg": false,
   "profile_image_url": "http://tp4.sinaimg.cn/5119417731/50/5696057764/1",
   "idstr": "5119417731",
   "verified": false,
   "geo_enabled": true,
   "class": 1,
   "screen_name": "\u521asir\u768410000\u5929\u542c\u5988\u5988\u7684\u8bdd\u9759\u599e",
   "lang": "zh-cn",
   "weihao": "",
   "remark": "",
   "favourites_count": 0,
   "name": "\u521asir\u768410000\u5929\u542c\u5988\u5988\u7684\u8bdd\u9759\u599e",
   "url": "",
   "gender": "m",
   "created_at": "Sat May 10 17:55:53 +0800 2014",
   "worldcup_guess": 0,
   "verified_type": -1,
   "following": false
  },
  "in_reply_to_status_id": "",
  "comments_count": 0,
  "geo": null,
  "id": 3728143254878339,
  "source": "<a href=\"http://app.weibo.com/t/feed/2o92Kh\" rel=\"nofollow\">vivo_Xplay</a>"
 },
 {
  "reposts_count": 0,
  "truncated": false,
  "text": "\u8fd9\u4e48\u591a\u7684\u6f02\u4eae\u65e5\u97e9\u6b27\u7f8e\u6742\u5fd7\u6b3eYY~~>>>>>>\u559c\u6b22\u70b9\u8fd9\u91cc\uff1ahttp://t.cn/RvESDA6",
  "visible": {
   "type": 0,
   "list_id": 0
  },
  "in_reply_to_status_id": "",
  "bmiddle_pic": "http://ww3.sinaimg.cn/bmiddle/e9820066jw1ehz8g71g90j20c80gjwgk.jpg",
  "id": 3728143254489321,
  "thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/e9820066jw1ehz8g71g90j20c80gjwgk.jpg",
  "mid": "3728143254489321",
  "source": "<a href=\"http://app.weibo.com/t/feed/5xCS0B\" rel=\"nofollow\">\u5fae\u535a\u624b\u673a\u7248</a>",
  "attitudes_count": 0,
  "in_reply_to_screen_name": "",
  "pic_urls": [
   {
    "thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/e9820066jw1ehz8g71g90j20c80gjwgk.jpg"
   }
  ],
  "in_reply_to_user_id": "",
  "darwin_tags": [],
  "favorited": false,
  "original_pic": "http://ww3.sinaimg.cn/large/e9820066jw1ehz8g71g90j20c80gjwgk.jpg",
  "idstr": "3728143254489321",
  "user": {
   "bi_followers_count": 44,
   "domain": "",
   "avatar_large": "http://tp3.sinaimg.cn/3917611110/180/5680332659/0",
   "verified_source": "",
   "ptype": 0,
   "statuses_count": 16879,
   "allow_all_comment": true,
   "id": 3917611110,
   "verified_reason_url": "",
   "city": "1000",
   "province": "71",
   "block_app": 0,
   "follow_me": false,
   "verified_reason": "",
   "followers_count": 292,
   "location": "\u53f0\u6e7e",
   "verified_trade": "",
   "mbtype": 0,
   "verified_source_url": "",
   "profile_url": "u/3917611110",
   "block_word": 0,
   "avatar_hd": "http://ww3.sinaimg.cn/crop.0.2.346.346.1024/e9820066jw1eaxb6we10wj209m09rgn1.jpg",
   "star": 0,
   "description": "",
   "friends_count": 1091,
   "online_status": 1,
   "mbrank": 0,
   "allow_all_act_msg": false,
   "profile_image_url": "http://tp3.sinaimg.cn/3917611110/50/5680332659/0",
   "idstr": "3917611110",
   "verified": false,
   "geo_enabled": true,
   "class": 1,
   "screen_name": "\u6d41\u884c\u7f8e\u642d\u6742\u5fd7",
   "lang": "zh-cn",
   "weihao": "",
   "remark": "",
   "favourites_count": 0,
   "name": "\u6d41\u884c\u7f8e\u642d\u6742\u5fd7",
   "url": "",
   "gender": "f",
   "created_at": "Sun Nov 24 17:10:30 +0800 2013",
   "worldcup_guess": 0,
   "verified_type": -1,
   "following": false
  },
  "geo": null,
  "created_at": "Thu Jul 03 07:01:20 +0800 2014",
  "mlevel": 0,
  "comments_count": 0
 },
 {
  "darwin_tags": [],
  "favorited": false,
  "mid": "3728143251104938",
  "in_reply_to_user_id": "",
  "truncated": false,
  "text": "\u708e\u708e\u590f\u65e5\uff0c\u60f3\u60f3\u81ea\u5df1\u90a3\u4e0d\u582a\u56de\u9996\u7684\u201c\u9017\u6bd4\u201d\u4e8b\uff0c\u7ed9\u8fd9\u4e2a\u70ed\u7684\u60f3\u5c4e\u7684\u5b63\u8282\u964d\u964d\u6e29\u4e5f\u4e0d\u5931\u4e3a\u4e00\u4e2a\u597d\u529e\u6cd5~~\u5c31\u7b97\u673a\u667a\u5982\u6211\u6709\u7684\u65f6\u5019\u4e5f\u62b5\u4e0d\u8fc7\u60b2\u50ac\u547d\u8fd0\u7684\u6298\u78e8\uff01 http://t.cn/Rvufq4y",
  "created_at": "Thu Jul 03 07:01:20 +0800 2014",
  "mlevel": 0,
  "reposts_count": 0,
  "idstr": "3728143251104938",
  "visible": {
   "type": 0,
   "list_id": 0
  },
  "attitudes_count": 0,
  "pic_urls": [],
  "in_reply_to_screen_name": "",
  "user": {
   "bi_followers_count": 3,
   "domain": "",
   "avatar_large": "http://tp2.sinaimg.cn/2776200377/180/5686197056/1",
   "verified_source": "",
   "ptype": 0,
   "statuses_count": 855,
   "allow_all_comment": true,
   "id": 2776200377,
   "verified_reason_url": "",
   "city": "6",
   "province": "43",
   "block_app": 0,
   "follow_me": false,
   "verified_reason": "",
   "followers_count": 106,
   "location": "\u6e56\u5357 \u5cb3\u9633",
   "verified_trade": "",
   "mbtype": 0,
   "verified_source_url": "",
   "profile_url": "u/2776200377",
   "block_word": 0,
   "avatar_hd": "http://ww2.sinaimg.cn/crop.0.0.200.200.1024/a57974b9jw1ed3s4if74zj205l05kwen.jpg",
   "star": 0,
   "description": "",
   "friends_count": 166,
   "online_status": 0,
   "mbrank": 0,
   "allow_all_act_msg": false,
   "profile_image_url": "http://tp2.sinaimg.cn/2776200377/50/5686197056/1",
   "idstr": "2776200377",
   "verified": false,
   "geo_enabled": true,
   "class": 1,
   "screen_name": "\u75db\u5fc3\u7684\u5b88\u62a4",
   "lang": "zh-cn",
   "weihao": "",
   "remark": "",
   "favourites_count": 0,
   "name": "\u75db\u5fc3\u7684\u5b88\u62a4",
   "url": "",
   "gender": "m",
   "created_at": "Tue May 22 09:36:02 +0800 2012",
   "worldcup_guess": 0,
   "verified_type": -1,
   "following": false
  },
  "in_reply_to_status_id": "",
  "comments_count": 0,
  "geo": null,
  "id": 3728143251104938,
  "source": "<a href=\"http://app.weibo.com/t/feed/2o92Kh\" rel=\"nofollow\">vivo_Xplay</a>"
 }
]

Python 获取新浪微博的最新公共微博

时间: 2024-08-25 07:52:46

Python 获取新浪微博的最新公共微博的相关文章

Python 获取新浪微博的热门话题 (API)

#!/usr/bin/python # -*- 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 = ''

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

用python获取新浪微博最近发布内容的时候调用 public_timeline()函数的返回值是个jsonDict对象,首先需要将该对象通过json.dumps函数转换成字符串,然后对该字符串用GBK进行编码和解码,注意编码的时候函数encode的第二个参数要使用ignore(默认是strict),以防止当解码错误的时候报错而使程序意外退出 . import webbrowser import sinaweibopy3 from time import sleep import json de

python获取微信公共平台消息列表和用户头像

转载需注明原文地址:http://blog.csdn.net/btyh17mxy/article/details/25207889 刚写的模拟登陆的方式从获取微信公众平台消息列表和用户头像的库,之后还会继续增加相关功能,github地址https://github.com/btyh17mxy/wxwall #!/usr/bin/env python # coding: UTF-8 import json import hashlib import re import random import

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

写在前面 当我们试图从新浪微博抓取数据时,我们会发现网页上提示未登录,无法查看其他用户的信息. 模拟登录是定向爬虫制作中一个必须克服的问题,只有这样才能爬取到更多的内容. 实现微博登录的方法有很多,一般我们在模拟登录时首选WAP版. 因为PC版网页源码中包括很多的js代码,提交的内容也更多,不适合机器模拟登录. 我们实现微博登录的大体思路是这样的: 用抓包工具把正常登录时要提交的字段都记录下来. 模拟提交这些字段. 判断是否登录成功. 原理很简单,让我们一步一步来实现吧. 一.抓包利器Fiddl

获取新浪微博cookie

之前也百度了一下如何获取新浪微博cookie,附上其中出现频率最高的教程的网址 https://www.douban.com/note/264976536/?start=0#32893498 自己按照上面的步骤试了一下,然后发现找不到weibo.com,然后就试了一下其他的 首先也是用chrome浏览器打开,F12打开(我的键盘好像没有转换,所以要用Fn+F12),或者右键->检查 其他..如图吧,找到然后复制cookie那一长串 为了验证,我顺带试了一下这个将Cookie作为访问微博的head

新浪微博技术架构分析-微博首席架构师杨卫华

新浪科技讯 11月16日下午消息,由新浪微博主办的中国首届微博开发者大会在北京举行,这是国内微博行业的首场技术盛宴.作为国内微博市场的绝对领军者,新浪微博将在此次大会上公布一系列针对开发者的扶持政策,以期与第三方开发者联手推动微博行业的整体发展.视频:中国首届微博开发者大会杨卫华演讲媒体来源:新浪科技 以下为演讲实录: 大家下午好,在座的大部分都是技术开发者,技术开发者往往对微博这个产品非常关心.最晚的一次,是12点多收到一个邮件说想了解一下微博底层是 怎么构架的.很多技术人员对微博的构架非常感

转载:新浪微博、腾讯微博、人人网授权连接

新浪微博.腾讯微博.人人网授权连接含一键发布PHP版 你是否有过这样的经历,每到一个网站都要求你注册一个账号,注册还有很多限制,比如用户名不能为数字特殊字符或汉字,密码要求是数字和字母的组合,长度也有限制.有时候注册的一个账号已经被别人注册了.久而久之注册的账号越来越多,密码也越来越多,导致我们自己都不记得注册的账号或密码是多少.这是一件非常痛苦的事情.而如今你可能经常看到各大网站上都有使用新浪微博.腾讯微博.人人网等连接登录的功能,这样做的好处当然免除了注册的烦恼. 以前我们常想要是一个QQ号

iOS开发项目篇—39获取用户未读的微博信息(信息提醒)

iOS开发项目篇—39获取用户未读的微博信息(信息提醒) 一.简单说明 1.实现效果       2.实现 (1)新建一个类,封装请求 查看新浪官方要求的请求参数 该类中的代码设计 YYUnreadCountParam.h文件 1 // YYUnreadCountParam.h 2 //封装请求参数的类 3 4 #import "YYBaseParam.h" 5 6 @interface YYUnreadCountParam : YYBaseParam 7 /**uid true in

Python获取免费的可用代理

Python获取免费的可用代理 在使用爬虫多次爬取同一站点时,常常会被站点的ip反爬虫机制给禁掉,这时就能够通过使用代理来解决.眼下网上有非常多提供最新免费代理列表的站点.这些列表里非常多的代理主机是可用的,可是也有一些是不可用的,因此须要进一步筛选.利用Python能够非常方便地筛选出可用的代理列表. 以提供免费代理信息的站点IPCN 国家地区免费代理为例,这里给出一个爬取此站点上提供的代理信息并筛选可用代理主机的程序.主要用到requests和lxml,详细代码为: # -*- coding