BaşlayınÜcretsiz Başlayın

Collecting data on keywords

Now that we've set up the authentication, we can begin to collect Twitter data. Recall that with the Streaming API, we will be collecting real-time Twitter data based on either a sample or filtered by a keyword.

In our example, we will collect data on any tweet mentioning #rstats or #python in the tweet text, username, or user description with the filter endpoint.

The SListener module has already been defined and imported for you.

Bu egzersiz

Analyzing Social Media Data in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Import Stream from tweepy.
  • Set keywords_to_track to a list containing #rstats and #python.
  • Pass the auth and listen objects to Stream.
  • Set the keyword argument track equals to keywords_to_track.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

from ____ import ____

# Set up words to track
keywords_to_track = ____

# Instantiate the SListener object 
listen = SListener(api)

# Instantiate the Stream object
stream = Stream(____, ____, access_token, access_token_secret)

# Begin collecting data
stream.filter(track = ____)
Kodu Düzenle ve Çalıştır