This demo program shows how to retrieve tweets of a user in twitter.
The output:
The code:
1 2 3 4 5 6 7 8 9 10 11 12 13 | import snscrape.modules.twitter as sntwitter import pandas as pd tweets_list1 = [] for i,tweet in enumerate(sntwitter.TwitterSearchScraper('from:AppsFactoryPH').get_items()): #declare a username if i>100: #number of tweets you want to scrape break tweets_list1.append([tweet.date, tweet.id, tweet.content, tweet.user.username]) #declare the attributes to be returned tweets_df1 = pd.DataFrame(tweets_list1, columns=['Datetime', 'Tweet Id', 'Text', 'Username']) print(tweets_df1.head(10)) |
No comments:
Post a Comment