Skip to main content

Unofficial library to scrape Twitter profiles and posts from Nitter instances

Project description

Unofficial Nitter 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 instance among those listed in https://github.com/zedeus/nitter/wiki/Instances.


Installation

pip install ntscraper

How to use

First, initialize the library:

from ntscraper import Nitter

scraper = Nitter()

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 5
  • 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.

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

Returns a dictionary of the profile's information.

Get random Nitter instance

random_instance = scraper.get_random_instance()

Returns a random Nitter instance.

To do list

  • Add scraping of posts and comments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ntscraper-0.1.1.tar.gz (7.7 kB view details)

Uploaded Source

File details

Details for the file ntscraper-0.1.1.tar.gz.

File metadata

  • Download URL: ntscraper-0.1.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for ntscraper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 023416179de1e0521d9699d014827ac748c0fb9ccb474fb92c8dc2ccd8858e76
MD5 b48e57c1c5fb8657fde0250c3a59ab34
BLAKE2b-256 8fe8afa3f133c6f15eaa48a4e08313f94e376ec4c111a3d965be1b510caefa4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page