how can you run snscrape command from a python script?

I don’t know if you found the solution, but I ran this code and that worked for me :

import pandas as pd
import snscrape.modules.twitter as sntwitter

tweet_collection = pd.DataFrame({
'Username':[],
'Date'=[],
'Likes'=[],
'Content'=[]})

for tweet in sntwitter.TwitterSearchScraper(f'since:{date_beg} until:{date_end} from:{twitter_account}').get_items():
    tweets_collection = tweets_candidats.append({
        "Username":tweet.user.username,
        "Date":tweet.date,
        "Tweet":tweet.content,
        "Likes":tweet.likeCount,},ignore_index=True)
tweets_candidats.to_csv('Path/file.csv')

You can find more detail in the code on git hub

Twitter snscrape arguments

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top