Skip to main content

Unofficial Nitter scraper

Note

Twitter has recently made some changes which affected every third party Twitter client, including Nitter. As a result, most Nitter instances have shut down or will shut down shortly. Even local instances are affected by this, so you may not be able to scrape as many tweets as expected, if at all.

The scraper

This is a simple library to scrape Nitter instances for tweets. It can:

  • search and scrape tweets with a certain term

  • search and scrape tweets with a certain hashtag

  • scrape tweets from a user profile

  • get profile information of a user, such as display name, username, number of tweets, profile picture ...

If the instance to use is not provided to the scraper, it will use a random public instance. If you can, please host your own instance in order to avoid overloading the public ones and letting Nitter stay alive for everyone. You can read more about that here: https://github.com/zedeus/nitter#installation.


Installation

pip install ntscraper

How to use

First, initialize the library:

from ntscraper import Nitter

scraper = Nitter(log_level=1, skip_instance_check=False)

The valid logging levels are:

  • None = no logs
  • 0 = only warning and error logs
  • 1 = previous + informational logs (default)

The skip_instance_check parameter is used to skip the check of the Nitter instances altogether during the execution of the script. If you use your own instance or trust the instance you are relying on, then you can skip set it to 'True', otherwise it's better to leave it to false.

Then, choose the proper function for what you want to do from the following.

Scrape tweets

github_hash_tweets = scraper.get_tweets("github", mode='hashtag')

bezos_tweets = scraper.get_tweets("JeffBezos", mode='user')

Parameters:

  • term: search term
  • mode: modality to scrape the tweets. Default is 'term' which will look for tweets containing the search term. Other modes are 'hashtag' to search for a hashtag and 'user' to scrape tweets from a user profile
  • number: number of tweets to scrape. Default is -1 (no limit).
  • since: date to start scraping from, formatted as YYYY-MM-DD. Default is None
  • until: date to stop scraping at, formatted as YYYY-MM-DD. Default is None
  • near: location to search tweets from. Default is None (anywhere)
  • language: language of the tweets to search. Default is None (any language). The language must be specified as a 2-letter ISO 639-1 code (e.g. 'en' for English, 'es' for Spanish, 'fr' for French ...)
  • to: user to which the tweets are directed. Default is None (any user). For example, if you want to search for tweets directed to @github, you would set this parameter to 'github'
  • replies: whether to include replies in the search. If 'filters' or 'exclude' are set, this is overridden. Default is False
  • filters: list of filters to apply to the search. Default is None. Valid filters are: 'nativeretweets', 'media', 'videos', 'news', 'verified', 'native_video', 'replies', 'links', 'images', 'safe', 'quote', 'pro_video'
  • exclude: list of filters to exclude from the search. Default is None. Valid filters are the same as above
  • max_retries: max retries to scrape a page. Default is 5
  • instance: Nitter instance to use. Default is None and will be chosen at random

Returns a dictionary with tweets and threads for the term.

Multiprocessing

You can also scrape multiple terms at once using multiprocessing:

terms = ["github", "bezos", "musk"]

results = scraper.get_tweets(terms, mode='term')

Each term will be scraped in a different process. The result will be a list of dictionaries, one for each term.

The multiprocessing code needs to run in a if __name__ == "__main__" block to avoid errors. With multiprocessing, only full logging is supported. Also, the number of processes is limited to the number of available cores on your machine.

NOTE: using multiprocessing on public instances is highly discouraged since it puts too much load on the servers and could potentially also get you rate limited. Please only use it on your local instance.

Get single tweet

tweet = scraper.get_tweet_by_id("x", "1826317783430303888")

Parameters:

  • username: username of the tweet's author
  • tweet_id: ID of the tweet
  • instane: Nitter instance to use. Default is None
  • max_retries: max retries to scrape a page. Default is 5

Returns a dictionary with the tweet's content.

Get profile information

bezos_information = scraper.get_profile_info("JeffBezos")

Parameters:

  • username: username of the page to scrape
  • max_retries: max retries to scrape a page. Default is 5
  • instance: Nitter instance to use. Default is None
  • mode: mode of fetching profile info. 'simple' for basic info, 'detail' for detailed info including following and followers lists. Default is 'simple'

Returns a dictionary of the profile's information.

Multiprocessing

As for the term scraping, you can also get info from multiple profiles at once using multiprocessing:

usernames = ["x", "github"]

results = scraper.get_profile_info(usernames)

Each user will be scraped in a different process. The result will be a list of dictionaries, one for each user.

The multiprocessing code needs to run in a if __name__ == "__main__" block to avoid errors. With multiprocessing, only full logging is supported. Also, the number of processes is limited to the number of available cores on your machine.

NOTE: using multiprocessing on public instances is highly discouraged since it puts too much load on the servers and could potentially also get you rate limited. Please only use it on your local instance.

Get random Nitter instance

random_instance = scraper.get_random_instance()

Returns a random Nitter instance.

Note

Due to recent changes on Twitter's side, some Nitter instances may not work properly even if they are marked as "working" on Nitter's wiki. If you have trouble scraping with a certain instance, try changing it and check if the problem persists.

To do list

  • Add scraping of individual posts with comments

Release files for ntscraper 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ntscraper 0.4.0
File Size Uploaded
ntscraper-0.4.0.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ntscraper 0.4.0
File Interpreter ABI Platform
ntscraper-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size:27.5 kB

Release files / ntscraper-0.4.0.tar.gz

Download URL ntscraper-0.4.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3fe6dcb4e4fcbbbfb5ab5afc4d3b9ce24d1dda4e1d465927910991849a3ecd7a
BLAKE2b-256 checksum
How to use checksums
fe8131d38704b2c40c413542772ce39786c2f07da92cec4d21c0a841962a0b2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / ntscraper-0.4.0-py3-none-any.whl

Download URL ntscraper-0.4.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04cde8e772e0b4836dc82c4fef695a372071c7e2e603c611c4ff8d1f72707e3c
BLAKE2b-256 checksum
How to use checksums
7149d0f1cac9028f2c34685950474be47d65755736d289b884f35f4bf11e1091
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.16

2 release files

0.3.15

2 release files

0.3.14

2 release files

0.3.11

2 release files

0.3.10

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page