First, make sure Python and Tweepy installed well, and the network setup well.

Then, you go to http://dev.twitter.com and log in ,and  go to my application, get your ckey/csecret/atoken/asecret

Then, we create the .py file: PS4.py:

from tweepy import Stream

from tweepy import OAuthHandler

from tweepy.streaming import StreamListener

import time

ckey = 'VUHR4W*******1ZSDEKQ'

csecret = 'BqJSl0dbI*************48qdmWKJ1CKmxKbl8JUw5k'

atoken = '2207681958******************BMx6UWBzEonhKkhkkeDEOJC'

asecret = 'GQTeOedbv*****************GnrsUrZR0ItMJ6BarJnKorI3'

class listener(StreamListener):

    def on_data(self, data):

        try:

##            print data

            date = data.split('created_at":"')[1].split('","id')[0]

            tweet = data.split(',"text":"')[1].split('","source')[0]

            screen_name = data.split(',"screen_name":"')[1].split('","location')[0]

            location = data.split(',"location":"')[1].split('","url')[0]

            followers_count = data.split(',"followers_count":')[1].split(',"friends_count')[0]

            saveThis = date+""+tweet+";;;"+screen_name+";;;"+location+";;;"+followers_count

            print saveThis

##            saveFile = open('twitDB11.txt','a')
##
## saveFile.write(saveThis)
##
## saveFile.write('\n')
##
## saveFile.close() return True except BaseException, e: print 'failed ondata,', str(e) time.sleep(5) def on_error(self, status): print status auth = OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) twitterStream = Stream(auth, listener()) twitterStream.filter(track=["PS4"])

Then, we open it and run it. Colleting data like this:

Wed Nov 27 03:47:29 +0000 2013:::Gamma Blue 11s or PS4?:::JVanlo_ST::::::105
Wed Nov 27 03:47:29 +0000 2013:::DuniaIndo: Shenmue developer doing GDC postmortem, PS4 architect Mark Cerny translating: The full schedule of s... http:\/\/t.co\/sdlHKPJMke:::SHENMUE_MEGA_RT::::::9
Wed Nov 27 03:47:29 +0000 2013:::Does anyone else have a PS4?:::CodyP_Texas54::::::61
Wed Nov 27 03:47:29 +0000 2013:::Wish #oomf would come over and play ps4 with me. :(:::rgvheat3::::::303
Wed Nov 27 03:47:30 +0000 2013:::ayuna_rachim: Shenmue developer doing GDC postmortem, PS4 architect Mark Cerny translating: The full schedule o... http:\/\/t.co\/riqqgFRZXj:::SHENMUE_MEGA_RT::::::9
Wed Nov 27 03:47:31 +0000 2013:::\u6700\u8fd1\u30c6\u30a4\u30eb\u30ba\u3068\u304bFF\u3068\u304bKH\u30b7\u30ea\u30fc\u30ba\u306e\u65b0\u4f5c\u767a\u8868\u3042\u308b\u3068\u5b09\u3057\u3044\u3068\u3068\u3082\u306bPS4\u304b\u3082\u3057\u308c\u306a\u3044\u4e0d\u5b89\u304c\u62bc\u3057\u5bc4\u305b\u3066\u304f\u308b:::xyuyuch18::::::279
Wed Nov 27 03:47:31 +0000 2013:::PlaneteGamers: #Games #News Shenmue developer doing GDC postmortem, PS4 architect Mark Cerny translating ... http:\/\/t.co\/m6DBhuQ92E:::SHENMUE_MEGA_RT::::::9
Wed Nov 27 03:47:31 +0000 2013:::RT @OFWG_Sheed: @Bflakes78 lol i might get ps4 i miss yall so much:::Bflakes78::::::1328
Wed Nov 27 03:47:31 +0000 2013:::\u3069\u3046\u305bPS4\u306a\u3093\u3060\u308d\u899a\u609f\u306f\u3067\u304d\u3066\u3044\u308b:::tana1003:::\u4eac\u90fd:::219
Wed Nov 27 03:47:32 +0000 2013:::onlinegmg: Shenmue developer doing GDC postmortem, PS4 architect Mark Cerny translating http:\/\/t.co\/lhEuMWPvel http:\/\/t.co\/hNrss8yfAD:::SHENMUE_MEGA_RT::::::9
Wed Nov 27 03:47:33 +0000 2013:::I liked a @YouTube video from @nobodyepic http:\/\/t.co\/w0aZnLUeow NobodyEpic 1,000,000 Subscriber Q&A Video (Battlefield 4: PS4:::GabGonzaRom::::::93
Wed Nov 27 03:47:34 +0000 2013:::PS4\u3060\u308d\uff1f:::eyck:::\u30a8\u30aa\u30eb\u30bc\u30a2:::859

python 使用 tweepy 案例: PS4的更多相关文章

  1. python模块使用案例

    python模块使用案例 一.使用MySQLdb模块代码示例: # 导入 MySQLdb模块 import MySQLdb # 和服务器建立链接,host是服务器ip,我的MySQL数据库搭建在本机, ...

  2. Python操作MySQL案例

    最近都在学习Python代码,希望学会Python后,能给我带来更高的工作效率,所以每天坚持学习和拷代码,下面是一个Python操作MySQL的一个实例,该实例可以让更多的人更好了解MySQLdb模块 ...

  3. python购物车小案例

    python购物车小案例# 案列描述:有一个小型水果店里面有水果(苹果:¥8/kg,香蕉:¥5/kg,芒果:¥15/kg,葡萄:¥12/kg),客户带了100元钱进店选购水果.# 1.客户输入相应序号 ...

  4. Python 简单爬虫案例

    Python 简单爬虫案例 import requests url = "https://www.sogou.com/web" # 封装参数 wd = input('enter a ...

  5. python + hadoop (案例)

    python如何链接hadoop,并且使用hadoop的资源,这篇文章介绍了一个简单的案例! 一.python的map/reduce代码 首先认为大家已经对haoop已经有了很多的了解,那么需要建立m ...

  6. python 爬虫入门----案例爬取上海租房图片

    前言 对于一个net开发这爬虫真真的以前没有写过.这段时间学习python爬虫,今天周末无聊写了一段代码爬取上海租房图片,其实很简短就是利用爬虫的第三方库Requests与BeautifulSoup. ...

  7. python面向对象封装案例(附:is和==的区别)

    面向对象封装案例 目标 封装 小明爱跑步 存放家具 01. 封装 封装 是面向对象编程的一大特点 面向对象编程的 第一步 —— 将 属性 和 方法 封装 到一个抽象的 类 中 外界 使用 类 创建 对 ...

  8. 朴素贝叶斯分类算法介绍及python代码实现案例

    朴素贝叶斯分类算法 1.朴素贝叶斯分类算法原理 1.1.概述 贝叶斯分类算法是一大类分类算法的总称 贝叶斯分类算法以样本可能属于某类的概率来作为分类依据 朴素贝叶斯分类算法是贝叶斯分类算法中最简单的一 ...

  9. python 面向对象编程案例01

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #面向对象编程案例01 class Behave(): def __init__(self,name): se ...

随机推荐

  1. css-下拉菜单案例

    <!DOCTYPE html>CSS4-布局2-display下拉菜单案例 <style>.xiala{width:200px;background:#ddd;}.xiala ...

  2. mysql数据库的连接

    public TJb checkjbByschool(long id)throws ClassNotFoundException,SQLException { Class.forName(" ...

  3. R语言学习笔记(数据的读取与保存)

    library(MASS)#载入package MASSdata(package="MASS") #查看MASS中的数据集data(SP500,package="MASS ...

  4. activiti笔记二:用户任务

    1, assignee 代替humanPerformer  功能 2, cadidateUsers代替potentialOwner功能 3, candidateGroups代替potentialOwn ...

  5. JQuery阻止表单提交的方法总结 - 使用onsubmit()验证表单并阻止非法提交

    方法1:<form onsubmit="javascript:confirm()"> 方法内返回false阻止表单提交 示例:代码检测textarea内填写的长度,未填 ...

  6. HTML5简单入门系列(七)

    前言 本篇详细介绍canvas画布的API.说是详细介绍,也只是一些常用的API及简单实例和说明.LZ本人也还没有看完全部,下篇会介绍剩余的一些内容. 本篇的示例中,LZ加入了注释,为的是只简单介绍A ...

  7. python的时间模块

    python有两个重要的时间模块,分别是time和datetime 先看time模块 表示时间的几种方法: 1)时间元组:time.struct_time(tm_year=2016,   tm_mon ...

  8. Bing必应(Yahoo雅虎)搜索引擎登录网站 - Blog透视镜

    Bing必应是微软的搜索引擎,原本是置放在MSN网站上的,微软重新开发并改为新的名子,只要连到官网,登录网站后,过了不久,搜索引擎就会用爬虫,来检索你的网站,等过了一阵子之后,自然就可以找到你的文章. ...

  9. linux系统文件夹的作用 good

    /bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 如:环境变量 /etc/rc.d 启动的配置文件和脚本 /home用户主目录的基点,比如用户user的主目录就是/ho ...

  10. C语言中指针的指针是如何工作的?

      我们有时看到这样地饿代码: int *ptr = &x; 这里,ptr是一个指向x在内存中的地址的指针. 假设有另外一条语句是这样地的: int **ptr2 = &ptr; 我们 ...