Twitter 从进程数据中的推文原始数据打印推文全文

Twitter 从进程数据中的推文原始数据打印推文全文,twitter,tweepy,Twitter,Tweepy,我正在从某个用户id流式发送推文,并使用一种方法处理推文数据以打印流式发送的推文 如何从下面的原始数据中获取tweet全文是我的代码 class MaxListener(tweepy.StreamListener): def on_data(self, raw_data): self.process_data(raw_data) return True def process_data(self, raw_data): pr

我正在从某个用户id流式发送推文,并使用一种方法处理推文数据以打印流式发送的推文

如何从下面的原始数据中获取tweet全文是我的代码


class MaxListener(tweepy.StreamListener):

    def on_data(self, raw_data):
        self.process_data(raw_data)

        return True

    def process_data(self, raw_data):
        print(raw_data)

    def on_error(self, status_code):
        if status_code == 420:
            return False

下面是原始数据的打印方式


{"created_at":"Fri May 07 06:31:29 +0000 2021","id":1390554865030647808,"id_str":"1390554865030647808","text":"On May 7, 1895 \u2013 In Saint Petersburg, Russian scientist Alexander Popov demonstrates to the Russian Physical and Ch\u2026 https:\/\/t.co\/FhCbeYTQjX","source":"\u003ca href=\"https:\/\/mobile.twitter.com\" rel=\"nofollow\"\u003eTwitter Web App\u003c\/a\u003e","truncated":true,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":824740868011745281,"id_str":"824740868011745281","name":"Wincelee","screen_name":"Wincelee2","location":"Maasai Mara University Kenya","url":"https:\/\/sites.google.com\/view\/manu-website\/home","description":"I wanna die on Mars too just not on impact","translator_type":"none","protected":false,"verified":false,"followers_count":40,"friends_count":385,"listed_count":0,"favourites_count":21,"statuses_count":362,"created_at":"Thu Jan 26 22:08:40 +0000 2017","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":null,"contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"FAB81E","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"000000","profile_text_color":"000000","profile_use_background_image":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1053591683785543680\/v15uC5Hy_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1053591683785543680\/v15uC5Hy_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/824740868011745281\/1512946471","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null,"withheld_in_countries":[]},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"extended_tweet":{"full_text":"On May 7, 1895 \u2013 In Saint Petersburg, Russian scientist Alexander Popov demonstrates to the Russian Physical and Chemical Society his invention, the Popov lightning detector\u2014a primitive radio receiver.","display_text_range":[0,201],"entities":{"hashtags":[],"urls":[],"user_mentions":[],"symbols":[]}},"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/FhCbeYTQjX","expanded_url":"https:\/\/twitter.com\/i\/web\/status\/1390554865030647808","display_url":"twitter.com\/i\/web\/status\/1\u2026","indices":[117,140]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en","timestamp_ms":"1620369089740"}

下面是我在process_data方法中所厌倦的内容


def process_data(self, raw_data):
        #print(raw_data)
        tweet = json.loads(raw_data)

        print(tweetInfo.full_text, "\n")

但是我得到了以下错误

AttributeError: 'str' object has no attribute 'full_text'


不知道你的代码是如何工作的,但是如果你说原始数据是发布的,那么它只是

print(raw_data['extended_tweet']['full_text'])
在你的代码中,
对于tweet中的tweetInfo:
意味着tweet是一个列表(或者是可编辑的),或者你正在尝试在tweet.keys()上迭代?

我只是想要这个打印(原始数据['extended\u tweet']['full\u text']),谢谢