Last active
March 24, 2018 06:04
-
-
Save nrmzmh/690c253eb7a022d9c1b21d8d0a5f100d to your computer and use it in GitHub Desktop.
Twitter Scraping (beginner)
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ada | |
adakah | |
adakan | |
adalah | |
adanya | |
adapun | |
agak | |
agar | |
akan | |
aku | |
akulah | |
akupun | |
al | |
alangkah | |
allah | |
amat | |
antara | |
antaramu | |
antaranya | |
apa | |
apa-apa | |
apabila | |
apakah | |
apapun | |
atas | |
atasmu | |
atasnya | |
atau | |
ataukah | |
ataupun | |
bagaimana | |
bagaimanakah | |
bagi | |
bagimu | |
baginya | |
bahawa | |
bahawasanya | |
bahkan | |
bahwa | |
banyak | |
banyaknya | |
barangsiapa | |
bawah | |
beberapa | |
begitu | |
begitupun | |
belaka | |
belum | |
belumkah | |
berada | |
berapa | |
berikan | |
beriman | |
berkenaan | |
berupa | |
beserta | |
biarpun | |
bila | |
bilakah | |
bilamana | |
bisa | |
boleh | |
bukan | |
bukankah | |
bukanlah | |
dahulu | |
dalam | |
dalamnya | |
dan | |
dapat | |
dapati | |
dapatkah | |
dapatlah | |
dari | |
daripada | |
daripadaku | |
daripadamu | |
daripadanya | |
demi | |
demikian | |
demikianlah | |
dengan | |
dengannya | |
di | |
dia | |
dialah | |
didapat | |
didapati | |
dimanakah | |
engkau | |
engkaukah | |
engkaulah | |
engkaupun | |
hai | |
hampir | |
hampir-hampir | |
hanya | |
hanyalah | |
hendak | |
hendaklah | |
hingga | |
ia | |
iaitu | |
ialah | |
ianya | |
inginkah | |
ini | |
inikah | |
inilah | |
itu | |
itukah | |
itulah | |
jadi | |
jangan | |
janganlah | |
jika | |
jikalau | |
jua | |
juapun | |
juga | |
kalau | |
kami | |
kamikah | |
kamipun | |
kamu | |
kamukah | |
kamupun | |
katakan | |
ke | |
kecuali | |
kelak | |
kembali | |
kemudian | |
kepada | |
kepadaku | |
kepadakulah | |
kepadamu | |
kepadanya | |
kepadanyalah | |
kerana | |
kerananya | |
kesan | |
ketika | |
kini | |
kita | |
ku | |
kurang | |
lagi | |
lain | |
lalu | |
lamanya | |
langsung | |
lebih | |
maha | |
mahu | |
mahukah | |
mahupun | |
maka | |
malah | |
mana | |
manakah | |
manapun | |
masih | |
masing | |
masing-masing | |
melainkan | |
memang | |
mempunyai | |
mendapat | |
mendapati | |
mendapatkan | |
mengadakan | |
mengapa | |
mengapakah | |
mengenai | |
menjadi | |
menyebabkan | |
menyebabkannya | |
mereka | |
merekalah | |
merekapun | |
meskipun | |
mu | |
nescaya | |
niscaya | |
nya | |
olah | |
oleh | |
orang | |
pada | |
padahal | |
padamu | |
padanya | |
paling | |
para | |
pasti | |
patut | |
patutkah | |
per | |
pergilah | |
perkara | |
perkaranya | |
perlu | |
pernah | |
pertama | |
pula | |
pun | |
sahaja | |
saja | |
saling | |
sama | |
sama-sama | |
samakah | |
sambil | |
sampai | |
sana | |
sangat | |
sangatlah | |
saya | |
se | |
seandainya | |
sebab | |
sebagai | |
sebagaimana | |
sebanyak | |
sebelum | |
sebelummu | |
sebelumnya | |
sebenarnya | |
secara | |
sedang | |
sedangkan | |
sedikit | |
sedikitpun | |
segala | |
sehingga | |
sejak | |
sekalian | |
sekalipun | |
sekarang | |
sekitar | |
selain | |
selalu | |
selama | |
selama-lamanya | |
seluruh | |
seluruhnya | |
sementara | |
semua | |
semuanya | |
semula | |
senantiasa | |
sendiri | |
sentiasa | |
seolah | |
seolah-olah | |
seorangpun | |
separuh | |
sepatutnya | |
seperti | |
seraya | |
sering | |
serta | |
seseorang | |
sesiapa | |
sesuatu | |
sesudah | |
sesudahnya | |
sesungguhnya | |
sesungguhnyakah | |
setelah | |
setiap | |
siapa | |
siapakah | |
sini | |
situ | |
situlah | |
suatu | |
sudah | |
sudahkah | |
sungguh | |
sungguhpun | |
supaya | |
tadinya | |
tahukah | |
tak | |
tanpa | |
tanya | |
tanyakanlah | |
tapi | |
telah | |
tentang | |
tentu | |
terdapat | |
terhadap | |
terhadapmu | |
termasuk | |
terpaksa | |
tertentu | |
tetapi | |
tiada | |
tiadakah | |
tiadalah | |
tiap | |
tiap-tiap | |
tidak | |
tidakkah | |
tidaklah | |
turut | |
untuk | |
untukmu | |
wahai | |
walau | |
walaupun | |
ya | |
yaini | |
yaitu | |
yakni | |
yang | |
terhadap | |
lagi | |
maha | |
pasal | |
utk | |
dapat | |
dpt | |
ade | |
ada | |
kita | |
ckp | |
je | |
saje | |
saja | |
bahawa | |
la | |
takde | |
tahu | |
rasa | |
rase | |
tp | |
kepada | |
kpd | |
tengok | |
tgk | |
yg | |
knp | |
kenapa | |
org | |
ko | |
kau | |
cite | |
dah | |
dh | |
sudah | |
xde | |
yg | |
lah | |
mkini | |
buat | |
membuat | |
mbuat | |
Cuma | |
news | |
� | |
kat | |
nak | |
bout | |
turut | |
itu | |
dok | |
dorang | |
lihat | |
takdak | |
dak | |
tak | |
mintak | |
bila | |
rupa | |
will | |
still | |
nak | |
faham | |
fahamkan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(twitteR) | |
library(tm) | |
library(textstem) | |
library(wordcloud2) | |
consumerKey = "XXXXXXX" | |
consumerSecret = "XXXXXXX" | |
accessToken = "XXXXXXX" | |
accessSecret = "XXXXXXX" | |
options(httr_oauth_cache=TRUE) | |
setup_twitter_oauth(consumer_key = consumerKey, | |
consumer_secret = consumerSecret, | |
access_token = accessToken, | |
access_secret = accessSecret) | |
# scrape tweets with hashtag, use searchTwitter(): | |
onemdb = searchTwitter("#1MDB exclude:retweets", n=3200) | |
# create data frame and save as .csv format | |
onemdb_df = tbl_df(map_df(onemdb, as.data.frame)) | |
write.csv(onemdb_df, "onemdb.csv") | |
# since my data also in Malay's Language | |
# So, i add some Malay stop words from my excel file | |
# Excel file only one column and contains the stop word | |
# You also can create your own stop words | |
# mstopwords : Malay stopwords | |
# nstopwords : New stopwords (English + Malay) | |
mstopwords = read.csv("malay_stop_word.csv", header = FALSE) | |
mstopwords = as.character(mstopwords$V1) | |
nstopwords = c(mstopwords, stopwords()) | |
# calling my twitter data that i save before onemdb.csv | |
# make sure the file is in your directory | |
# you can check by using dir() function to check the file is already in your directory or not | |
text1 = read.csv("oneMDB.csv", header = FALSE) | |
text = text1$V2 # i only interested with data at column 2 | |
text = VectorSource(text) | |
text = Corpus(text) | |
text = tm_map(text, content_transformer(tolower)) | |
text = tm_map(text, removeWords, nstopwords) | |
text = tm_map(text, stripWhitespace) | |
docs1 = lemmatize_strings(text)[1] | |
b = str_split(docs1,"[,]") | |
b = unlist(b) | |
b[1] = gsub(pattern="[(\"]","",b[1]) | |
str_sub(b[1],1,1) = " " | |
docs2 = Corpus(VectorSource(b)) | |
docs2 = tm_map(docs2,removePunctuation) | |
docs2 = tm_map(docs2,stripWhitespace) | |
docs2 = tm_map(docs2, removeWords, nstopwords) | |
dtmr = DocumentTermMatrix(docs2,control=list(wordLengths=c(2,20), | |
bounds=list(global=c(2,30)))) | |
freqr = colSums(as.matrix(dtmr)) | |
wf = data.frame(names(freqr),freqr) | |
names(wf) = c("TERM","FREQ") | |
# create cloud by default | |
wordcloud2(wf) | |
# You also can create the letterCloud | |
letterCloud(wf,word="1MDB",color="random-light", | |
backgroundColor="black",size=0.5, fontFamily = "Comic Sans MS") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment