Home > Net >  How to get only tweets from Snscrape?
How to get only tweets from Snscrape?

Time:02-01

After scraping data from Twitter using Snscrape, I am unable to get only tweets. Under the column for tweet.sourceLabel, I am getting a mixture of twitter, instagram and foursquare.

import snscrape.modules.twitter as sntwitter
keyword = '(COVID OR Corona Vírus)'
maxTweets = 30
tweets = []

for i,tweet in enumerate(sntwitter.TwitterSearchScraper(keyword   ' since:2020-01-01 lang:pt').get_items()) :
    if i > maxTweets :
        break
    tweets.append([tweet.date, tweet.id, tweet.content, tweet.user.username, tweet.sourceLabel])

CodePudding user response:

I'm not seeing any other social media other than Twitter for tweet.sourceLabel. I have fixed few typos in your code as well.

import snscrape.modules.twitter as sntwitter
keyword = '(COVID OR Corona Vírus)'
maxTweets = 30
tweets = []

for i,tweet in enumerate(sntwitter.TwitterSearchScraper(keyword   ' since:2020-01-01 lang:pt').get_items()) :
    if i > maxTweets :
        break
    tweets.append([tweet.sourceLabel])

print(tweets)

Output: enter image description here

  • Related