Loading and accessing tweets
In the video, we loaded a tweet we collected using tweepy into Python. Tweets arrive from the Streaming API in JSON format and need to be converted into a Python data structure.
In this exercise, we'll load a single tweet into Python and print out some fields.
The tweet JSON has been loaded for you and is stored in tweet_json.
Bài tập này là một phần của khóa học
Analyzing Social Media Data in Python
Hướng dẫn bài tập
- Import the
jsonmodule. - Convert the tweet JSON stored in
tweet_jsonfrom JSON to Python object usingjson's.loads()method. - Print the tweet text and id using the appropriate keys.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
# Load JSON
import ____
# Convert from JSON to Python object
tweet = ____.____(tweet_json)
# Print tweet text
print(tweet[____])
# Print tweet id
print(tweet[____])