-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCrawling_Twitter.py
66 lines (39 loc) · 1.05 KB
/
Crawling_Twitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# coding: utf-8
# In[7]:
import tweepy
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import time
import json
# In[8]:
access_token = "xxx"
access_token_secret = "xxxxx"
consumer_key = "xxxxxxxxxxxxx"
consumer_secret = "Xxxxxx"
# In[9]:
class StdoutListener(StreamListener):
def on_data(self,data):
try:
data = json.loads(data)
tweet = data['text']
with open('tweet.csv', 'a', encoding='utf-8') as f:
saveFile = open('gabung.csv','a')
f.write(tweet)
f.write('\n')
f.close()
return True
except BaseException as e:
print('Failed'(e))
def on_error(self_status):
print(status)
# In[10]:
#streaming
l = StdoutListener()
auth = OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)
stream = Stream(auth,l)
stream.filter(track=['nonton'])
# In[ ]:
# In[ ]: