Spaces:
Runtime error
Runtime error
Mosa
commited on
Commit
•
c5c6036
1
Parent(s):
39fded5
I fixed mentioned issues.
Browse files- .idea/misc.xml +1 -1
- .idea/politweet.iml +1 -0
- twitter-scraper/scrape.py +67 -54
- twitter-scraper/twitter_scraper.ipynb +392 -153
.idea/misc.xml
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<project version="4">
|
3 |
-
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.
|
4 |
</project>
|
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<project version="4">
|
3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (politweet)" project-jdk-type="Python SDK" />
|
4 |
</project>
|
.idea/politweet.iml
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
<component name="NewModuleRootManager">
|
4 |
<content url="file://$MODULE_DIR$">
|
5 |
<excludeFolder url="file://$MODULE_DIR$/politweet-environment" />
|
|
|
6 |
</content>
|
7 |
<orderEntry type="inheritedJdk" />
|
8 |
<orderEntry type="sourceFolder" forTests="false" />
|
|
|
3 |
<component name="NewModuleRootManager">
|
4 |
<content url="file://$MODULE_DIR$">
|
5 |
<excludeFolder url="file://$MODULE_DIR$/politweet-environment" />
|
6 |
+
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
7 |
</content>
|
8 |
<orderEntry type="inheritedJdk" />
|
9 |
<orderEntry type="sourceFolder" forTests="false" />
|
twitter-scraper/scrape.py
CHANGED
@@ -1,51 +1,58 @@
|
|
1 |
-
|
2 |
-
from tkinter import EXCEPTION
|
3 |
import twint
|
4 |
from datetime import date
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
self.from_date = from_date
|
16 |
self.to_date = to_date
|
17 |
self.num_tweets = num_tweets
|
18 |
self.conf = twint.Config()
|
19 |
|
20 |
-
def scrape_by_user(self,_user):
|
21 |
-
|
22 |
-
self.conf.Search = "from:@" + _user
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
def scrape_by_user_and_string(self,_user:str,_string:str):
|
|
|
30 |
self.conf.Username = _user
|
31 |
-
self.conf.Search = _string
|
32 |
-
return self.
|
33 |
|
34 |
-
def
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
40 |
indx_replies.append(i)
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
#
|
45 |
-
|
|
|
46 |
|
47 |
-
def
|
48 |
-
|
49 |
tweet info is a dataframe with fallowing columns
|
50 |
Index(['id', 'conversation_id', 'created_at', 'date', 'timezone', 'place',
|
51 |
'tweet', 'language', 'hashtags', 'cashtags', 'user_id', 'user_id_str',
|
@@ -53,25 +60,31 @@ class scraper:
|
|
53 |
'thumbnail', 'retweet', 'nlikes', 'nreplies', 'nretweets', 'quote_url',
|
54 |
'search', 'near', 'geo', 'source', 'user_rt_id', 'user_rt',
|
55 |
'retweet_id', 'reply_to', 'retweet_date', 'translate', 'trans_src',
|
56 |
-
'trans_dest']
|
57 |
-
we just pick the relevant ones.
|
58 |
c is a twint.Config() object
|
59 |
-
|
60 |
-
|
61 |
-
self.conf.
|
62 |
-
self.conf.
|
|
|
63 |
self.conf.Since = self.from_date
|
64 |
self.conf.Until = self.to_date
|
65 |
-
self.conf.Hide_output = True
|
66 |
-
twint.run.Search(self.conf)
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
return
|
71 |
-
def __check_date_type(d1,d2):
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import twint
|
2 |
from datetime import date
|
3 |
+
|
4 |
+
class TwitterScraper(object):
|
5 |
+
"""
|
6 |
+
This class is a twitter TwitterScraper called TwitterScraper. It takes the user as input and collects the user's tweets
|
7 |
+
from 'from_date' to 'to_date'. If 'from_date' and 'to_date' are not specified, it collects the number of tweets 'num_tweets' from today.
|
8 |
+
It outputs a dictionary with the tweet unique id and some other information.
|
9 |
+
input: user, from_date, to_date, num_tweets
|
10 |
+
output: dict
|
11 |
+
"""
|
12 |
+
def __init__(self, from_date="2006-07-01", to_date=str(date.today()), num_tweets=20):
|
13 |
self.from_date = from_date
|
14 |
self.to_date = to_date
|
15 |
self.num_tweets = num_tweets
|
16 |
self.conf = twint.Config()
|
17 |
|
18 |
+
def scrape_by_user(self, _user):
|
19 |
+
"""This method uses twint to extract tweets based on username"""
|
20 |
+
self.conf.Search = "from:@" + _user # is the search configuration is given in this format it searches after
|
21 |
+
# user_names.
|
22 |
+
return self.__get_tweets__from_twint__()
|
23 |
+
|
24 |
+
def scrape_by_string(self, _string: str):
|
25 |
+
"""This method uses twint to extract tweets based on string.
|
26 |
+
all extracted tweets have the specified word in _string parameter in it.
|
27 |
+
"""
|
28 |
+
self.conf.Search = _string # this tells twint configuration to search for string
|
29 |
+
return self.__get_tweets__from_twint__()
|
30 |
|
31 |
+
def scrape_by_user_and_string(self, _user: str, _string: str):
|
32 |
+
"""This method uses twint to extract tweets brased on string and username"""
|
33 |
self.conf.Username = _user
|
34 |
+
self.conf.Search = _string
|
35 |
+
return self.__get_tweets__from_twint__()
|
36 |
|
37 |
+
def get_only_tweets(self, tweet_and_replies_info):
|
38 |
+
tweet_and_replies = tweet_and_replies_info["tweet"]
|
39 |
+
"""
|
40 |
+
This functions input arg is a data frame (the output from scrape methords ) and removes...
|
41 |
+
all tweets starting with \"@\" which is indicator of a reply or retweet.
|
42 |
+
"""
|
43 |
+
indx_replies = []
|
44 |
+
for i in range(len(tweet_and_replies)):
|
45 |
+
if tweet_and_replies[i].startswith("@"):
|
46 |
indx_replies.append(i)
|
47 |
|
48 |
+
tweets_info = tweet_and_replies_info.drop(labels=indx_replies, axis=0)
|
49 |
+
# drop removes the columns which its index specified by
|
50 |
+
# indx_replies. axis=0 if we want to delete rows.
|
51 |
+
#print(len(tweets['tweet']), " of them are Tweets")
|
52 |
+
return tweets_info
|
53 |
|
54 |
+
def __get_tweets__from_twint__(self):
|
55 |
+
""" __get_tweets_from_twint__
|
56 |
tweet info is a dataframe with fallowing columns
|
57 |
Index(['id', 'conversation_id', 'created_at', 'date', 'timezone', 'place',
|
58 |
'tweet', 'language', 'hashtags', 'cashtags', 'user_id', 'user_id_str',
|
|
|
60 |
'thumbnail', 'retweet', 'nlikes', 'nreplies', 'nretweets', 'quote_url',
|
61 |
'search', 'near', 'geo', 'source', 'user_rt_id', 'user_rt',
|
62 |
'retweet_id', 'reply_to', 'retweet_date', 'translate', 'trans_src',
|
63 |
+
'trans_dest']
|
64 |
+
we just pick the relevant ones.
|
65 |
c is a twint.Config() object
|
66 |
+
we also configure twint output.
|
67 |
+
"""
|
68 |
+
self.conf.Pandas = True #
|
69 |
+
self.conf.Count = True #
|
70 |
+
self.conf.Limit = self.num_tweets # specifies how many tweet should be scraped
|
71 |
self.conf.Since = self.from_date
|
72 |
self.conf.Until = self.to_date
|
73 |
+
self.conf.Hide_output = True # Hides the output. If set to False it will prints tweets in the terminal window.
|
74 |
+
twint.run.Search(self.conf)
|
75 |
+
tweet_and_replies_inf = twint.output.panda.Tweets_df # here we say that output souldwe dataframe.
|
76 |
+
tweet_and_replies_inf = tweet_and_replies_inf[
|
77 |
+
["id", "tweet", "date", "user_id", "username", "urls", 'nlikes', 'nreplies', 'nretweets']]
|
78 |
+
return tweet_and_replies_inf
|
79 |
+
# def __check_date_type(d1,d2): if (type(d1) or type(d2)) is not type("str"): # If the type of ite date input
|
80 |
+
# is not string it generates exception print("[!] Please make sure the date is a string in this format
|
81 |
+
# \"yyyy-mm-dd\" ") raise EXCEPTION("Incorrect date type Exception!") elif (len(d1.split("-")) or len(d2.split(
|
82 |
+
# "-")))<2: print("[!] Please make sure the date is a string in this format \"yyyy-mm-dd\" ") raise EXCEPTION(
|
83 |
+
# "Incorrect date type Exception!")
|
84 |
+
|
85 |
+
|
86 |
+
if __name__ == "__main__":
|
87 |
+
sc = TwitterScraper(num_tweets=10)
|
88 |
+
dc = sc.scrape_by_string("jimmieakesson")
|
89 |
+
print(dc.head())
|
90 |
+
print(type(dc))
|
twitter-scraper/twitter_scraper.ipynb
CHANGED
@@ -54,7 +54,7 @@
|
|
54 |
"outputs": [],
|
55 |
"source": [
|
56 |
"import scrape\n",
|
57 |
-
"sc= scrape.
|
58 |
]
|
59 |
},
|
60 |
{
|
@@ -67,7 +67,7 @@
|
|
67 |
"name": "stdout",
|
68 |
"output_type": "stream",
|
69 |
"text": [
|
70 |
-
"[+] Finished: Successfully collected
|
71 |
]
|
72 |
},
|
73 |
{
|
@@ -105,61 +105,197 @@
|
|
105 |
" <tbody>\n",
|
106 |
" <tr>\n",
|
107 |
" <th>0</th>\n",
|
108 |
-
" <td>
|
109 |
-
" <td>
|
110 |
-
" <td>2022-
|
111 |
-
" <td>
|
112 |
-
" <td>
|
113 |
" <td>[]</td>\n",
|
114 |
-
" <td>
|
115 |
" <td>0</td>\n",
|
116 |
" <td>0</td>\n",
|
117 |
" </tr>\n",
|
118 |
" <tr>\n",
|
119 |
-
" <th>
|
120 |
-
" <td>
|
121 |
-
" <td
|
122 |
-
" <td>2022-
|
123 |
-
" <td>
|
124 |
-
" <td>
|
125 |
-
" <td>[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
" <td>0</td>\n",
|
127 |
" <td>0</td>\n",
|
128 |
" <td>0</td>\n",
|
129 |
" </tr>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
" <tr>\n",
|
131 |
-
" <th>
|
132 |
-
" <td>
|
133 |
-
" <td>
|
134 |
-
" <td>2022-
|
135 |
-
" <td>
|
136 |
-
" <td>
|
137 |
" <td>[]</td>\n",
|
|
|
|
|
138 |
" <td>0</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
" <td>0</td>\n",
|
140 |
" <td>0</td>\n",
|
141 |
" </tr>\n",
|
142 |
" <tr>\n",
|
143 |
-
" <th>
|
144 |
-
" <td>
|
145 |
-
" <td>
|
146 |
-
" <td>2022-
|
147 |
-
" <td>
|
148 |
-
" <td>
|
149 |
" <td>[]</td>\n",
|
150 |
" <td>0</td>\n",
|
151 |
" <td>0</td>\n",
|
152 |
" <td>0</td>\n",
|
153 |
" </tr>\n",
|
154 |
" <tr>\n",
|
155 |
-
" <th>
|
156 |
-
" <td>
|
157 |
-
" <td>
|
158 |
-
" <td>2022-
|
159 |
-
" <td>
|
160 |
-
" <td>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
" <td>[]</td>\n",
|
162 |
-
" <td>
|
163 |
" <td>0</td>\n",
|
164 |
" <td>0</td>\n",
|
165 |
" </tr>\n",
|
@@ -169,40 +305,40 @@
|
|
169 |
],
|
170 |
"text/plain": [
|
171 |
" id tweet \\\n",
|
172 |
-
"0
|
173 |
-
"
|
174 |
-
"
|
175 |
-
"
|
176 |
-
"
|
177 |
"\n",
|
178 |
-
" date user_id
|
179 |
-
"0 2022-
|
180 |
-
"
|
181 |
-
"
|
182 |
-
"
|
183 |
-
"
|
184 |
"\n",
|
185 |
-
"
|
186 |
-
"0
|
187 |
-
"
|
188 |
-
"
|
189 |
-
"
|
190 |
-
"
|
191 |
]
|
192 |
},
|
193 |
-
"execution_count":
|
194 |
"metadata": {},
|
195 |
"output_type": "execute_result"
|
196 |
}
|
197 |
],
|
198 |
"source": [
|
199 |
-
"
|
200 |
-
"
|
201 |
]
|
202 |
},
|
203 |
{
|
204 |
"cell_type": "code",
|
205 |
-
"execution_count":
|
206 |
"id": "a7912a91",
|
207 |
"metadata": {},
|
208 |
"outputs": [
|
@@ -210,7 +346,7 @@
|
|
210 |
"name": "stdout",
|
211 |
"output_type": "stream",
|
212 |
"text": [
|
213 |
-
"[+] Finished: Successfully collected
|
214 |
]
|
215 |
},
|
216 |
{
|
@@ -247,31 +383,55 @@
|
|
247 |
" </thead>\n",
|
248 |
" <tbody>\n",
|
249 |
" <tr>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
" <th>1</th>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
" <td>1537770920621879297</td>\n",
|
252 |
" <td>Man kan ha synpunkter på en sådan lösning, men...</td>\n",
|
253 |
" <td>2022-06-17 14:15:32</td>\n",
|
254 |
" <td>95972673</td>\n",
|
255 |
" <td>jimmieakesson</td>\n",
|
256 |
" <td>[]</td>\n",
|
257 |
-
" <td>
|
258 |
" <td>17</td>\n",
|
259 |
" <td>41</td>\n",
|
260 |
" </tr>\n",
|
261 |
" <tr>\n",
|
262 |
-
" <th>
|
263 |
" <td>1537770809225273344</td>\n",
|
264 |
" <td>Är det ont om plats på anstalterna så får man ...</td>\n",
|
265 |
" <td>2022-06-17 14:15:05</td>\n",
|
266 |
" <td>95972673</td>\n",
|
267 |
" <td>jimmieakesson</td>\n",
|
268 |
" <td>[]</td>\n",
|
269 |
-
" <td>
|
270 |
" <td>26</td>\n",
|
271 |
" <td>57</td>\n",
|
272 |
" </tr>\n",
|
273 |
" <tr>\n",
|
274 |
-
" <th>
|
275 |
" <td>1537770713368735744</td>\n",
|
276 |
" <td>Döms man för brott, särskilt våldsbrott, ska m...</td>\n",
|
277 |
" <td>2022-06-17 14:14:43</td>\n",
|
@@ -282,86 +442,64 @@
|
|
282 |
" <td>26</td>\n",
|
283 |
" <td>86</td>\n",
|
284 |
" </tr>\n",
|
285 |
-
" <tr>\n",
|
286 |
-
" <th>4</th>\n",
|
287 |
-
" <td>1537770657823576066</td>\n",
|
288 |
-
" <td>Platsbrist? Jaha, vad spelar det för roll? D...</td>\n",
|
289 |
-
" <td>2022-06-17 14:14:29</td>\n",
|
290 |
-
" <td>95972673</td>\n",
|
291 |
-
" <td>jimmieakesson</td>\n",
|
292 |
-
" <td>[https://sverigesradio.se/artikel/domda-kvinno...</td>\n",
|
293 |
-
" <td>1152</td>\n",
|
294 |
-
" <td>85</td>\n",
|
295 |
-
" <td>132</td>\n",
|
296 |
-
" </tr>\n",
|
297 |
-
" <tr>\n",
|
298 |
-
" <th>5</th>\n",
|
299 |
-
" <td>1534230353094885383</td>\n",
|
300 |
-
" <td>Det är ytterst beklagligt att Magdalena Anders...</td>\n",
|
301 |
-
" <td>2022-06-07 19:46:35</td>\n",
|
302 |
-
" <td>95972673</td>\n",
|
303 |
-
" <td>jimmieakesson</td>\n",
|
304 |
-
" <td>[]</td>\n",
|
305 |
-
" <td>6121</td>\n",
|
306 |
-
" <td>546</td>\n",
|
307 |
-
" <td>557</td>\n",
|
308 |
-
" </tr>\n",
|
309 |
" </tbody>\n",
|
310 |
"</table>\n",
|
311 |
"</div>"
|
312 |
],
|
313 |
"text/plain": [
|
314 |
" id tweet \\\n",
|
315 |
-
"
|
316 |
-
"
|
317 |
-
"
|
318 |
-
"
|
319 |
-
"
|
320 |
-
"\n",
|
321 |
-
" date user_id username \\\n",
|
322 |
-
"1 2022-06-17 14:15:32 95972673 jimmieakesson \n",
|
323 |
-
"2 2022-06-17 14:15:05 95972673 jimmieakesson \n",
|
324 |
-
"3 2022-06-17 14:14:43 95972673 jimmieakesson \n",
|
325 |
-
"4 2022-06-17 14:14:29 95972673 jimmieakesson \n",
|
326 |
-
"5 2022-06-07 19:46:35 95972673 jimmieakesson \n",
|
327 |
"\n",
|
328 |
-
"
|
329 |
-
"
|
330 |
-
"
|
331 |
-
"
|
332 |
-
"
|
333 |
-
"
|
334 |
"\n",
|
335 |
" nretweets \n",
|
336 |
-
"
|
337 |
-
"
|
338 |
-
"
|
339 |
-
"
|
340 |
-
"
|
341 |
]
|
342 |
},
|
343 |
-
"execution_count":
|
344 |
"metadata": {},
|
345 |
"output_type": "execute_result"
|
346 |
}
|
347 |
],
|
348 |
"source": [
|
349 |
-
"
|
350 |
"df.head()"
|
351 |
]
|
352 |
},
|
353 |
{
|
354 |
"cell_type": "code",
|
355 |
-
"execution_count":
|
356 |
"id": "7db69757",
|
357 |
"metadata": {},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
"outputs": [
|
359 |
{
|
360 |
"name": "stdout",
|
361 |
"output_type": "stream",
|
362 |
"text": [
|
363 |
-
"[!] No more data! Scraping will stop now.\n",
|
364 |
-
"found 0 deleted tweets in this search.\n",
|
365 |
"[+] Finished: Successfully collected 16 Tweets from @jimmieakesson.\n"
|
366 |
]
|
367 |
},
|
@@ -418,7 +556,7 @@
|
|
418 |
" <td>95972673</td>\n",
|
419 |
" <td>jimmieakesson</td>\n",
|
420 |
" <td>[]</td>\n",
|
421 |
-
" <td>
|
422 |
" <td>9</td>\n",
|
423 |
" <td>68</td>\n",
|
424 |
" </tr>\n",
|
@@ -430,7 +568,7 @@
|
|
430 |
" <td>95972673</td>\n",
|
431 |
" <td>jimmieakesson</td>\n",
|
432 |
" <td>[]</td>\n",
|
433 |
-
" <td>
|
434 |
" <td>199</td>\n",
|
435 |
" <td>336</td>\n",
|
436 |
" </tr>\n",
|
@@ -472,8 +610,8 @@
|
|
472 |
"\n",
|
473 |
" date user_id username urls nlikes nreplies \\\n",
|
474 |
"0 2021-02-20 11:07:50 95972673 jimmieakesson [] 1277 22 \n",
|
475 |
-
"1 2021-02-20 11:06:58 95972673 jimmieakesson []
|
476 |
-
"2 2021-02-20 11:06:45 95972673 jimmieakesson []
|
477 |
"3 2021-02-19 14:00:01 95972673 jimmieakesson [] 1334 55 \n",
|
478 |
"4 2021-02-18 15:31:53 95972673 jimmieakesson [] 3044 268 \n",
|
479 |
"\n",
|
@@ -485,57 +623,158 @@
|
|
485 |
"4 404 "
|
486 |
]
|
487 |
},
|
488 |
-
"execution_count":
|
489 |
"metadata": {},
|
490 |
"output_type": "execute_result"
|
491 |
}
|
492 |
],
|
493 |
"source": [
|
494 |
-
"
|
495 |
-
"
|
496 |
]
|
497 |
},
|
498 |
{
|
499 |
"cell_type": "code",
|
500 |
-
"execution_count":
|
501 |
-
"id": "
|
502 |
"metadata": {},
|
503 |
"outputs": [
|
504 |
{
|
505 |
-
"
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
}
|
538 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
539 |
"source": [
|
540 |
"tweets= df[\"tweet\"]\n",
|
541 |
"for tweet in tweets:\n",
|
|
|
54 |
"outputs": [],
|
55 |
"source": [
|
56 |
"import scrape\n",
|
57 |
+
"sc= scrape.TwitterScraper(num_tweets=10)\n"
|
58 |
]
|
59 |
},
|
60 |
{
|
|
|
67 |
"name": "stdout",
|
68 |
"output_type": "stream",
|
69 |
"text": [
|
70 |
+
"[+] Finished: Successfully collected 20 Tweets.\n"
|
71 |
]
|
72 |
},
|
73 |
{
|
|
|
105 |
" <tbody>\n",
|
106 |
" <tr>\n",
|
107 |
" <th>0</th>\n",
|
108 |
+
" <td>1545194541006950400</td>\n",
|
109 |
+
" <td>kim sever benim gibi sevmeyecekler bıraktığın ...</td>\n",
|
110 |
+
" <td>2022-07-08 01:54:21</td>\n",
|
111 |
+
" <td>1396065566117466113</td>\n",
|
112 |
+
" <td>heja4r</td>\n",
|
113 |
" <td>[]</td>\n",
|
114 |
+
" <td>1</td>\n",
|
115 |
" <td>0</td>\n",
|
116 |
" <td>0</td>\n",
|
117 |
" </tr>\n",
|
118 |
" <tr>\n",
|
119 |
+
" <th>1</th>\n",
|
120 |
+
" <td>1545192735354806274</td>\n",
|
121 |
+
" <td>Kelimeler,albayım,bazı anlamalara gelmiyor..</td>\n",
|
122 |
+
" <td>2022-07-08 01:47:11</td>\n",
|
123 |
+
" <td>1481604485118140425</td>\n",
|
124 |
+
" <td>Theguapo6</td>\n",
|
125 |
+
" <td>[]</td>\n",
|
126 |
+
" <td>1</td>\n",
|
127 |
+
" <td>0</td>\n",
|
128 |
+
" <td>0</td>\n",
|
129 |
+
" </tr>\n",
|
130 |
+
" <tr>\n",
|
131 |
+
" <th>2</th>\n",
|
132 |
+
" <td>1545190168533008385</td>\n",
|
133 |
+
" <td>@shikan213 ptdr ? y’a aucune racisme à quel mo...</td>\n",
|
134 |
+
" <td>2022-07-08 01:36:59</td>\n",
|
135 |
+
" <td>1476042813741617155</td>\n",
|
136 |
+
" <td>srndz213__</td>\n",
|
137 |
+
" <td>[]</td>\n",
|
138 |
+
" <td>0</td>\n",
|
139 |
+
" <td>1</td>\n",
|
140 |
+
" <td>0</td>\n",
|
141 |
+
" </tr>\n",
|
142 |
+
" <tr>\n",
|
143 |
+
" <th>3</th>\n",
|
144 |
+
" <td>1545190106910171136</td>\n",
|
145 |
+
" <td>@guzzeida Men gud du har presterat så mkt bätt...</td>\n",
|
146 |
+
" <td>2022-07-08 01:36:44</td>\n",
|
147 |
+
" <td>34343541</td>\n",
|
148 |
+
" <td>lisaxamanda</td>\n",
|
149 |
+
" <td>[]</td>\n",
|
150 |
+
" <td>1</td>\n",
|
151 |
+
" <td>0</td>\n",
|
152 |
+
" <td>0</td>\n",
|
153 |
+
" </tr>\n",
|
154 |
+
" <tr>\n",
|
155 |
+
" <th>4</th>\n",
|
156 |
+
" <td>1545190096042860544</td>\n",
|
157 |
+
" <td>Heja, heja, heja Slovensko</td>\n",
|
158 |
+
" <td>2022-07-08 01:36:41</td>\n",
|
159 |
+
" <td>3158344237</td>\n",
|
160 |
+
" <td>ian_10_19</td>\n",
|
161 |
+
" <td>[]</td>\n",
|
162 |
" <td>0</td>\n",
|
163 |
" <td>0</td>\n",
|
164 |
" <td>0</td>\n",
|
165 |
" </tr>\n",
|
166 |
+
" </tbody>\n",
|
167 |
+
"</table>\n",
|
168 |
+
"</div>"
|
169 |
+
],
|
170 |
+
"text/plain": [
|
171 |
+
" id tweet \\\n",
|
172 |
+
"0 1545194541006950400 kim sever benim gibi sevmeyecekler bıraktığın ... \n",
|
173 |
+
"1 1545192735354806274 Kelimeler,albayım,bazı anlamalara gelmiyor.. \n",
|
174 |
+
"2 1545190168533008385 @shikan213 ptdr ? y’a aucune racisme à quel mo... \n",
|
175 |
+
"3 1545190106910171136 @guzzeida Men gud du har presterat så mkt bätt... \n",
|
176 |
+
"4 1545190096042860544 Heja, heja, heja Slovensko \n",
|
177 |
+
"\n",
|
178 |
+
" date user_id username urls nlikes \\\n",
|
179 |
+
"0 2022-07-08 01:54:21 1396065566117466113 heja4r [] 1 \n",
|
180 |
+
"1 2022-07-08 01:47:11 1481604485118140425 Theguapo6 [] 1 \n",
|
181 |
+
"2 2022-07-08 01:36:59 1476042813741617155 srndz213__ [] 0 \n",
|
182 |
+
"3 2022-07-08 01:36:44 34343541 lisaxamanda [] 1 \n",
|
183 |
+
"4 2022-07-08 01:36:41 3158344237 ian_10_19 [] 0 \n",
|
184 |
+
"\n",
|
185 |
+
" nreplies nretweets \n",
|
186 |
+
"0 0 0 \n",
|
187 |
+
"1 0 0 \n",
|
188 |
+
"2 1 0 \n",
|
189 |
+
"3 0 0 \n",
|
190 |
+
"4 0 0 "
|
191 |
+
]
|
192 |
+
},
|
193 |
+
"execution_count": 5,
|
194 |
+
"metadata": {},
|
195 |
+
"output_type": "execute_result"
|
196 |
+
}
|
197 |
+
],
|
198 |
+
"source": [
|
199 |
+
"string_tr_info=sc.scrape_by_string(\"heja\")\n",
|
200 |
+
"string_tr_info.head()\n"
|
201 |
+
]
|
202 |
+
},
|
203 |
+
{
|
204 |
+
"cell_type": "code",
|
205 |
+
"execution_count": 6,
|
206 |
+
"id": "902170ad",
|
207 |
+
"metadata": {},
|
208 |
+
"outputs": [
|
209 |
+
{
|
210 |
+
"data": {
|
211 |
+
"text/html": [
|
212 |
+
"<div>\n",
|
213 |
+
"<style scoped>\n",
|
214 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
215 |
+
" vertical-align: middle;\n",
|
216 |
+
" }\n",
|
217 |
+
"\n",
|
218 |
+
" .dataframe tbody tr th {\n",
|
219 |
+
" vertical-align: top;\n",
|
220 |
+
" }\n",
|
221 |
+
"\n",
|
222 |
+
" .dataframe thead th {\n",
|
223 |
+
" text-align: right;\n",
|
224 |
+
" }\n",
|
225 |
+
"</style>\n",
|
226 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
227 |
+
" <thead>\n",
|
228 |
+
" <tr style=\"text-align: right;\">\n",
|
229 |
+
" <th></th>\n",
|
230 |
+
" <th>id</th>\n",
|
231 |
+
" <th>tweet</th>\n",
|
232 |
+
" <th>date</th>\n",
|
233 |
+
" <th>user_id</th>\n",
|
234 |
+
" <th>username</th>\n",
|
235 |
+
" <th>urls</th>\n",
|
236 |
+
" <th>nlikes</th>\n",
|
237 |
+
" <th>nreplies</th>\n",
|
238 |
+
" <th>nretweets</th>\n",
|
239 |
+
" </tr>\n",
|
240 |
+
" </thead>\n",
|
241 |
+
" <tbody>\n",
|
242 |
" <tr>\n",
|
243 |
+
" <th>0</th>\n",
|
244 |
+
" <td>1545194541006950400</td>\n",
|
245 |
+
" <td>kim sever benim gibi sevmeyecekler bıraktığın ...</td>\n",
|
246 |
+
" <td>2022-07-08 01:54:21</td>\n",
|
247 |
+
" <td>1396065566117466113</td>\n",
|
248 |
+
" <td>heja4r</td>\n",
|
249 |
" <td>[]</td>\n",
|
250 |
+
" <td>1</td>\n",
|
251 |
+
" <td>0</td>\n",
|
252 |
" <td>0</td>\n",
|
253 |
+
" </tr>\n",
|
254 |
+
" <tr>\n",
|
255 |
+
" <th>1</th>\n",
|
256 |
+
" <td>1545192735354806274</td>\n",
|
257 |
+
" <td>Kelimeler,albayım,bazı anlamalara gelmiyor..</td>\n",
|
258 |
+
" <td>2022-07-08 01:47:11</td>\n",
|
259 |
+
" <td>1481604485118140425</td>\n",
|
260 |
+
" <td>Theguapo6</td>\n",
|
261 |
+
" <td>[]</td>\n",
|
262 |
+
" <td>1</td>\n",
|
263 |
" <td>0</td>\n",
|
264 |
" <td>0</td>\n",
|
265 |
" </tr>\n",
|
266 |
" <tr>\n",
|
267 |
+
" <th>4</th>\n",
|
268 |
+
" <td>1545190096042860544</td>\n",
|
269 |
+
" <td>Heja, heja, heja Slovensko</td>\n",
|
270 |
+
" <td>2022-07-08 01:36:41</td>\n",
|
271 |
+
" <td>3158344237</td>\n",
|
272 |
+
" <td>ian_10_19</td>\n",
|
273 |
" <td>[]</td>\n",
|
274 |
" <td>0</td>\n",
|
275 |
" <td>0</td>\n",
|
276 |
" <td>0</td>\n",
|
277 |
" </tr>\n",
|
278 |
" <tr>\n",
|
279 |
+
" <th>6</th>\n",
|
280 |
+
" <td>1545189783747436545</td>\n",
|
281 |
+
" <td>Beni sorarsan dardayım..</td>\n",
|
282 |
+
" <td>2022-07-08 01:35:27</td>\n",
|
283 |
+
" <td>1481604485118140425</td>\n",
|
284 |
+
" <td>Theguapo6</td>\n",
|
285 |
+
" <td>[]</td>\n",
|
286 |
+
" <td>2</td>\n",
|
287 |
+
" <td>0</td>\n",
|
288 |
+
" <td>0</td>\n",
|
289 |
+
" </tr>\n",
|
290 |
+
" <tr>\n",
|
291 |
+
" <th>12</th>\n",
|
292 |
+
" <td>1545186234623991813</td>\n",
|
293 |
+
" <td>Heja strandhäll. Vilket jävla block mongo</td>\n",
|
294 |
+
" <td>2022-07-08 01:21:21</td>\n",
|
295 |
+
" <td>1160537136250195968</td>\n",
|
296 |
+
" <td>Siggydunn</td>\n",
|
297 |
" <td>[]</td>\n",
|
298 |
+
" <td>0</td>\n",
|
299 |
" <td>0</td>\n",
|
300 |
" <td>0</td>\n",
|
301 |
" </tr>\n",
|
|
|
305 |
],
|
306 |
"text/plain": [
|
307 |
" id tweet \\\n",
|
308 |
+
"0 1545194541006950400 kim sever benim gibi sevmeyecekler bıraktığın ... \n",
|
309 |
+
"1 1545192735354806274 Kelimeler,albayım,bazı anlamalara gelmiyor.. \n",
|
310 |
+
"4 1545190096042860544 Heja, heja, heja Slovensko \n",
|
311 |
+
"6 1545189783747436545 Beni sorarsan dardayım.. \n",
|
312 |
+
"12 1545186234623991813 Heja strandhäll. Vilket jävla block mongo \n",
|
313 |
"\n",
|
314 |
+
" date user_id username urls nlikes \\\n",
|
315 |
+
"0 2022-07-08 01:54:21 1396065566117466113 heja4r [] 1 \n",
|
316 |
+
"1 2022-07-08 01:47:11 1481604485118140425 Theguapo6 [] 1 \n",
|
317 |
+
"4 2022-07-08 01:36:41 3158344237 ian_10_19 [] 0 \n",
|
318 |
+
"6 2022-07-08 01:35:27 1481604485118140425 Theguapo6 [] 2 \n",
|
319 |
+
"12 2022-07-08 01:21:21 1160537136250195968 Siggydunn [] 0 \n",
|
320 |
"\n",
|
321 |
+
" nreplies nretweets \n",
|
322 |
+
"0 0 0 \n",
|
323 |
+
"1 0 0 \n",
|
324 |
+
"4 0 0 \n",
|
325 |
+
"6 0 0 \n",
|
326 |
+
"12 0 0 "
|
327 |
]
|
328 |
},
|
329 |
+
"execution_count": 6,
|
330 |
"metadata": {},
|
331 |
"output_type": "execute_result"
|
332 |
}
|
333 |
],
|
334 |
"source": [
|
335 |
+
"string_t_info=sc.get_only_tweets(tr_info)\n",
|
336 |
+
"string_t_info.head()"
|
337 |
]
|
338 |
},
|
339 |
{
|
340 |
"cell_type": "code",
|
341 |
+
"execution_count": 7,
|
342 |
"id": "a7912a91",
|
343 |
"metadata": {},
|
344 |
"outputs": [
|
|
|
346 |
"name": "stdout",
|
347 |
"output_type": "stream",
|
348 |
"text": [
|
349 |
+
"[+] Finished: Successfully collected 20 Tweets.\n"
|
350 |
]
|
351 |
},
|
352 |
{
|
|
|
383 |
" </thead>\n",
|
384 |
" <tbody>\n",
|
385 |
" <tr>\n",
|
386 |
+
" <th>0</th>\n",
|
387 |
+
" <td>1544748873767424001</td>\n",
|
388 |
+
" <td>Fruktansvärt att nås av beskedet att kvinnan s...</td>\n",
|
389 |
+
" <td>2022-07-06 20:23:26</td>\n",
|
390 |
+
" <td>95972673</td>\n",
|
391 |
+
" <td>jimmieakesson</td>\n",
|
392 |
+
" <td>[]</td>\n",
|
393 |
+
" <td>3397</td>\n",
|
394 |
+
" <td>167</td>\n",
|
395 |
+
" <td>140</td>\n",
|
396 |
+
" </tr>\n",
|
397 |
+
" <tr>\n",
|
398 |
" <th>1</th>\n",
|
399 |
+
" <td>1538948369611210764</td>\n",
|
400 |
+
" <td>@annieloof Nej, jag håller med. Tänk mer som M...</td>\n",
|
401 |
+
" <td>2022-06-20 20:14:18</td>\n",
|
402 |
+
" <td>95972673</td>\n",
|
403 |
+
" <td>jimmieakesson</td>\n",
|
404 |
+
" <td>[]</td>\n",
|
405 |
+
" <td>1513</td>\n",
|
406 |
+
" <td>89</td>\n",
|
407 |
+
" <td>115</td>\n",
|
408 |
+
" </tr>\n",
|
409 |
+
" <tr>\n",
|
410 |
+
" <th>2</th>\n",
|
411 |
" <td>1537770920621879297</td>\n",
|
412 |
" <td>Man kan ha synpunkter på en sådan lösning, men...</td>\n",
|
413 |
" <td>2022-06-17 14:15:32</td>\n",
|
414 |
" <td>95972673</td>\n",
|
415 |
" <td>jimmieakesson</td>\n",
|
416 |
" <td>[]</td>\n",
|
417 |
+
" <td>694</td>\n",
|
418 |
" <td>17</td>\n",
|
419 |
" <td>41</td>\n",
|
420 |
" </tr>\n",
|
421 |
" <tr>\n",
|
422 |
+
" <th>3</th>\n",
|
423 |
" <td>1537770809225273344</td>\n",
|
424 |
" <td>Är det ont om plats på anstalterna så får man ...</td>\n",
|
425 |
" <td>2022-06-17 14:15:05</td>\n",
|
426 |
" <td>95972673</td>\n",
|
427 |
" <td>jimmieakesson</td>\n",
|
428 |
" <td>[]</td>\n",
|
429 |
+
" <td>810</td>\n",
|
430 |
" <td>26</td>\n",
|
431 |
" <td>57</td>\n",
|
432 |
" </tr>\n",
|
433 |
" <tr>\n",
|
434 |
+
" <th>4</th>\n",
|
435 |
" <td>1537770713368735744</td>\n",
|
436 |
" <td>Döms man för brott, särskilt våldsbrott, ska m...</td>\n",
|
437 |
" <td>2022-06-17 14:14:43</td>\n",
|
|
|
442 |
" <td>26</td>\n",
|
443 |
" <td>86</td>\n",
|
444 |
" </tr>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
" </tbody>\n",
|
446 |
"</table>\n",
|
447 |
"</div>"
|
448 |
],
|
449 |
"text/plain": [
|
450 |
" id tweet \\\n",
|
451 |
+
"0 1544748873767424001 Fruktansvärt att nås av beskedet att kvinnan s... \n",
|
452 |
+
"1 1538948369611210764 @annieloof Nej, jag håller med. Tänk mer som M... \n",
|
453 |
+
"2 1537770920621879297 Man kan ha synpunkter på en sådan lösning, men... \n",
|
454 |
+
"3 1537770809225273344 Är det ont om plats på anstalterna så får man ... \n",
|
455 |
+
"4 1537770713368735744 Döms man för brott, särskilt våldsbrott, ska m... \n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
"\n",
|
457 |
+
" date user_id username urls nlikes nreplies \\\n",
|
458 |
+
"0 2022-07-06 20:23:26 95972673 jimmieakesson [] 3397 167 \n",
|
459 |
+
"1 2022-06-20 20:14:18 95972673 jimmieakesson [] 1513 89 \n",
|
460 |
+
"2 2022-06-17 14:15:32 95972673 jimmieakesson [] 694 17 \n",
|
461 |
+
"3 2022-06-17 14:15:05 95972673 jimmieakesson [] 810 26 \n",
|
462 |
+
"4 2022-06-17 14:14:43 95972673 jimmieakesson [] 1020 26 \n",
|
463 |
"\n",
|
464 |
" nretweets \n",
|
465 |
+
"0 140 \n",
|
466 |
+
"1 115 \n",
|
467 |
+
"2 41 \n",
|
468 |
+
"3 57 \n",
|
469 |
+
"4 86 "
|
470 |
]
|
471 |
},
|
472 |
+
"execution_count": 7,
|
473 |
"metadata": {},
|
474 |
"output_type": "execute_result"
|
475 |
}
|
476 |
],
|
477 |
"source": [
|
478 |
+
"user__tr_info=sc.scrape_by_user(\"jimmieakesson\")\n",
|
479 |
"df.head()"
|
480 |
]
|
481 |
},
|
482 |
{
|
483 |
"cell_type": "code",
|
484 |
+
"execution_count": null,
|
485 |
"id": "7db69757",
|
486 |
"metadata": {},
|
487 |
+
"outputs": [],
|
488 |
+
"source": [
|
489 |
+
"user__t_info=sc.get_only_tweets(tr_info)\n",
|
490 |
+
"user__t_info.head()"
|
491 |
+
]
|
492 |
+
},
|
493 |
+
{
|
494 |
+
"cell_type": "code",
|
495 |
+
"execution_count": 8,
|
496 |
+
"id": "9d6b1bdf",
|
497 |
+
"metadata": {},
|
498 |
"outputs": [
|
499 |
{
|
500 |
"name": "stdout",
|
501 |
"output_type": "stream",
|
502 |
"text": [
|
|
|
|
|
503 |
"[+] Finished: Successfully collected 16 Tweets from @jimmieakesson.\n"
|
504 |
]
|
505 |
},
|
|
|
556 |
" <td>95972673</td>\n",
|
557 |
" <td>jimmieakesson</td>\n",
|
558 |
" <td>[]</td>\n",
|
559 |
+
" <td>625</td>\n",
|
560 |
" <td>9</td>\n",
|
561 |
" <td>68</td>\n",
|
562 |
" </tr>\n",
|
|
|
568 |
" <td>95972673</td>\n",
|
569 |
" <td>jimmieakesson</td>\n",
|
570 |
" <td>[]</td>\n",
|
571 |
+
" <td>2458</td>\n",
|
572 |
" <td>199</td>\n",
|
573 |
" <td>336</td>\n",
|
574 |
" </tr>\n",
|
|
|
610 |
"\n",
|
611 |
" date user_id username urls nlikes nreplies \\\n",
|
612 |
"0 2021-02-20 11:07:50 95972673 jimmieakesson [] 1277 22 \n",
|
613 |
+
"1 2021-02-20 11:06:58 95972673 jimmieakesson [] 625 9 \n",
|
614 |
+
"2 2021-02-20 11:06:45 95972673 jimmieakesson [] 2458 199 \n",
|
615 |
"3 2021-02-19 14:00:01 95972673 jimmieakesson [] 1334 55 \n",
|
616 |
"4 2021-02-18 15:31:53 95972673 jimmieakesson [] 3044 268 \n",
|
617 |
"\n",
|
|
|
623 |
"4 404 "
|
624 |
]
|
625 |
},
|
626 |
+
"execution_count": 8,
|
627 |
"metadata": {},
|
628 |
"output_type": "execute_result"
|
629 |
}
|
630 |
],
|
631 |
"source": [
|
632 |
+
"user__string_tr_info=sc.scrape_by_user_and_string(\"jimmieakesson\",\"invandring\")\n",
|
633 |
+
"user__string_tr_info.head()\n"
|
634 |
]
|
635 |
},
|
636 |
{
|
637 |
"cell_type": "code",
|
638 |
+
"execution_count": 9,
|
639 |
+
"id": "a1aede79",
|
640 |
"metadata": {},
|
641 |
"outputs": [
|
642 |
{
|
643 |
+
"data": {
|
644 |
+
"text/html": [
|
645 |
+
"<div>\n",
|
646 |
+
"<style scoped>\n",
|
647 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
648 |
+
" vertical-align: middle;\n",
|
649 |
+
" }\n",
|
650 |
+
"\n",
|
651 |
+
" .dataframe tbody tr th {\n",
|
652 |
+
" vertical-align: top;\n",
|
653 |
+
" }\n",
|
654 |
+
"\n",
|
655 |
+
" .dataframe thead th {\n",
|
656 |
+
" text-align: right;\n",
|
657 |
+
" }\n",
|
658 |
+
"</style>\n",
|
659 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
660 |
+
" <thead>\n",
|
661 |
+
" <tr style=\"text-align: right;\">\n",
|
662 |
+
" <th></th>\n",
|
663 |
+
" <th>id</th>\n",
|
664 |
+
" <th>tweet</th>\n",
|
665 |
+
" <th>date</th>\n",
|
666 |
+
" <th>user_id</th>\n",
|
667 |
+
" <th>username</th>\n",
|
668 |
+
" <th>urls</th>\n",
|
669 |
+
" <th>nlikes</th>\n",
|
670 |
+
" <th>nreplies</th>\n",
|
671 |
+
" <th>nretweets</th>\n",
|
672 |
+
" </tr>\n",
|
673 |
+
" </thead>\n",
|
674 |
+
" <tbody>\n",
|
675 |
+
" <tr>\n",
|
676 |
+
" <th>0</th>\n",
|
677 |
+
" <td>1363067834260201475</td>\n",
|
678 |
+
" <td>Utan massiv, asylrelaterad invandring från frä...</td>\n",
|
679 |
+
" <td>2021-02-20 11:07:50</td>\n",
|
680 |
+
" <td>95972673</td>\n",
|
681 |
+
" <td>jimmieakesson</td>\n",
|
682 |
+
" <td>[]</td>\n",
|
683 |
+
" <td>1277</td>\n",
|
684 |
+
" <td>22</td>\n",
|
685 |
+
" <td>105</td>\n",
|
686 |
+
" </tr>\n",
|
687 |
+
" <tr>\n",
|
688 |
+
" <th>1</th>\n",
|
689 |
+
" <td>1363067613660778496</td>\n",
|
690 |
+
" <td>Många vänsterliberaler tycks ha reagerat på de...</td>\n",
|
691 |
+
" <td>2021-02-20 11:06:58</td>\n",
|
692 |
+
" <td>95972673</td>\n",
|
693 |
+
" <td>jimmieakesson</td>\n",
|
694 |
+
" <td>[]</td>\n",
|
695 |
+
" <td>625</td>\n",
|
696 |
+
" <td>9</td>\n",
|
697 |
+
" <td>68</td>\n",
|
698 |
+
" </tr>\n",
|
699 |
+
" <tr>\n",
|
700 |
+
" <th>2</th>\n",
|
701 |
+
" <td>1363067558409158656</td>\n",
|
702 |
+
" <td>Jag förstår — uppriktigt — inte den närmast hy...</td>\n",
|
703 |
+
" <td>2021-02-20 11:06:45</td>\n",
|
704 |
+
" <td>95972673</td>\n",
|
705 |
+
" <td>jimmieakesson</td>\n",
|
706 |
+
" <td>[]</td>\n",
|
707 |
+
" <td>2458</td>\n",
|
708 |
+
" <td>199</td>\n",
|
709 |
+
" <td>336</td>\n",
|
710 |
+
" </tr>\n",
|
711 |
+
" <tr>\n",
|
712 |
+
" <th>3</th>\n",
|
713 |
+
" <td>1362748777552113670</td>\n",
|
714 |
+
" <td>Invandring av hundratusentals människor från f...</td>\n",
|
715 |
+
" <td>2021-02-19 14:00:01</td>\n",
|
716 |
+
" <td>95972673</td>\n",
|
717 |
+
" <td>jimmieakesson</td>\n",
|
718 |
+
" <td>[]</td>\n",
|
719 |
+
" <td>1334</td>\n",
|
720 |
+
" <td>55</td>\n",
|
721 |
+
" <td>101</td>\n",
|
722 |
+
" </tr>\n",
|
723 |
+
" <tr>\n",
|
724 |
+
" <th>4</th>\n",
|
725 |
+
" <td>1362409505557012490</td>\n",
|
726 |
+
" <td>Vårt land behöver ett totalstopp för all asyl-...</td>\n",
|
727 |
+
" <td>2021-02-18 15:31:53</td>\n",
|
728 |
+
" <td>95972673</td>\n",
|
729 |
+
" <td>jimmieakesson</td>\n",
|
730 |
+
" <td>[]</td>\n",
|
731 |
+
" <td>3044</td>\n",
|
732 |
+
" <td>268</td>\n",
|
733 |
+
" <td>404</td>\n",
|
734 |
+
" </tr>\n",
|
735 |
+
" </tbody>\n",
|
736 |
+
"</table>\n",
|
737 |
+
"</div>"
|
738 |
+
],
|
739 |
+
"text/plain": [
|
740 |
+
" id tweet \\\n",
|
741 |
+
"0 1363067834260201475 Utan massiv, asylrelaterad invandring från frä... \n",
|
742 |
+
"1 1363067613660778496 Många vänsterliberaler tycks ha reagerat på de... \n",
|
743 |
+
"2 1363067558409158656 Jag förstår — uppriktigt — inte den närmast hy... \n",
|
744 |
+
"3 1362748777552113670 Invandring av hundratusentals människor från f... \n",
|
745 |
+
"4 1362409505557012490 Vårt land behöver ett totalstopp för all asyl-... \n",
|
746 |
+
"\n",
|
747 |
+
" date user_id username urls nlikes nreplies \\\n",
|
748 |
+
"0 2021-02-20 11:07:50 95972673 jimmieakesson [] 1277 22 \n",
|
749 |
+
"1 2021-02-20 11:06:58 95972673 jimmieakesson [] 625 9 \n",
|
750 |
+
"2 2021-02-20 11:06:45 95972673 jimmieakesson [] 2458 199 \n",
|
751 |
+
"3 2021-02-19 14:00:01 95972673 jimmieakesson [] 1334 55 \n",
|
752 |
+
"4 2021-02-18 15:31:53 95972673 jimmieakesson [] 3044 268 \n",
|
753 |
+
"\n",
|
754 |
+
" nretweets \n",
|
755 |
+
"0 105 \n",
|
756 |
+
"1 68 \n",
|
757 |
+
"2 336 \n",
|
758 |
+
"3 101 \n",
|
759 |
+
"4 404 "
|
760 |
+
]
|
761 |
+
},
|
762 |
+
"execution_count": 9,
|
763 |
+
"metadata": {},
|
764 |
+
"output_type": "execute_result"
|
765 |
}
|
766 |
],
|
767 |
+
"source": [
|
768 |
+
"user__string_t_info = sc.get_only_tweets(user__string_tr_info)\n",
|
769 |
+
"user__string_t_info.head()"
|
770 |
+
]
|
771 |
+
},
|
772 |
+
{
|
773 |
+
"cell_type": "code",
|
774 |
+
"execution_count": null,
|
775 |
+
"id": "48d50b46",
|
776 |
+
"metadata": {},
|
777 |
+
"outputs": [],
|
778 |
"source": [
|
779 |
"tweets= df[\"tweet\"]\n",
|
780 |
"for tweet in tweets:\n",
|