What it is
SNScrape is a Python library for scraping social networking services such as Twitter, Facebook, Reddit, and more. It allows fetching posts, comments, tweets, user profiles, and other social data without using official APIs.
SNScrape can scrape posts, tweets, users, and hashtags from multiple social platforms. It supports filtering by date, keyword, or user, and outputs data in JSON, CSV, or other formats.
Installation
pip install snscrapeGetting started
The smallest useful thing you can do with it, and what each part means.
import snscrape.modules.twitter as sntwitter
for i, tweet in enumerate(sntwitter.TwitterUserScraper('twitter').get_items()):
if i > 5:
break
print(tweet.date, tweet.content)import snscrape.modules.twitter as sntwitter
for i, tweet in enumerate(sntwitter.TwitterHashtagScraper('#Python').get_items()):
if i > 5:
break
print(tweet.date, tweet.content)Advanced usage
Where the library earns its place over a simpler alternative.
import snscrape.modules.twitter as sntwitter
import pandas as pd
tweets = []
for i, tweet in enumerate(sntwitter.TwitterSearchScraper('Python since:2025-01-01 until:2025-01-31').get_items()):
if i > 50:
break
tweets.append([tweet.date, tweet.user.username, tweet.content])
df = pd.DataFrame(tweets, columns=['Date','User','Content'])
df.to_csv('tweets.csv', index=False)import snscrape.modules.reddit as snreddit
for post in snreddit.RedditSearchScraper('Python').get_items():
print(post.title, post.url)import snscrape.modules.twitter as sntwitter
for tweet in sntwitter.TwitterSearchScraper('Python since:2025-08-01 until:2025-08-21').get_items():
print(tweet.date, tweet.content)Errors and fixes
The failures you are most likely to hit, and what actually resolves them.
- HTTPError / ConnectionError
- Check network connectivity or retry after a short delay.
- ValueError: invalid query
- Ensure the search query syntax matches the scraper's supported format.
Best practices
- Limit the number of items to scrape to avoid excessive requests.
- Use pandas DataFrame or CSV to store and analyze scraped data efficiently.
- Be mindful of platform usage terms to avoid scraping sensitive or restricted data.
- Combine with Python date filters to scrape relevant time periods.
- Use try/except to handle exceptions and network issues.
Background
Why it exists, and what it was reacting to.
SNScrape was created to provide a simple and reliable way to extract social media content without relying on official APIs, which often have rate limits or require authentication. It has become popular among data analysts, researchers, and developers for social media mining and analysis.
