如何从直接消息中获取文本?

时间:2016-04-01 15:03:21

标签: twitter tweepy

这个问题与tweepy库有关。

我正在使用命令(如下)获取收到的最新直接消息。我想获取消息的user_id和文本并回复。 但是,我无法理解如何提取文本。有帮助吗?

api.direct_messages(count=1)

简单地打印消息时,这就是它返回的内容:

[DirectMessage(sender=User(statuses_count=8452, verified=False, _json={'default_profile_image': False, 'statuses_count': 8452, 'following': True, 'verified': False, 'entities': {'description': {'urls': []}}, 'profile_background_image_url': 'http://pbs.twimg.com/profile_background_images/7904887943048/ab960e4a9bfeb7dd71c91e5b4f5c9dd1.jpeg', 'screen_name': 'xxxtnb', 'is_translation_enabled': False, 'id': 448743511, 'id_str': '448473511', 'notifications': False, 'name': 'Xxx Xxx', 'profile_text_color': '1C1F23', 'profile_background_tile': True, 'location': 'xxxx', 'default_profile': False, 'profile_use_background_image': True, 'profile_sidebar_fill_color': 'C9C9C9', 'lang': 'en', 'protected': False, 'has_extended_profile': False, 'profile_background_color': '07090B', 'is_translator': False, 'created_at': 'Fri Jun 05 11:39:26 +0000 2009', 'contributors_enabled': False, 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/3788000004442443400505954094/26ac579d33b26ee9e6748a3563fe3754dc_normal.png', 'profile_banner_url': 'https://pbs.twimg.com/profile_banners/44873556411/135934873965', 'time_zone': 'xxxx', 'description': '|DSECRIPTION|', 'listed_count': 2, 'profile_sidebar_border_color': 'FFFFFF', 'followers_count': 296, 'favourites_count': 19, 'geo_enabled': False, 'friends_count': 2332, 'profile_background_image_url_https': 'https://pbs.twimg.com/profile_background_images/79048873328/ab960e433a9bfeb7dd71c91e5b4f5c9dd1.jpeg', 'follow_request_sent': False, 'utc_offset': 25200, 'profile_image_url': 'http://pbs.twimg.com/profile_images/378800000324505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png', 'url': None, 'profile_link_color': 'C34242'}, id=44843473511, screen_name='xxxtnb', profile_background_image_url='http://pbs.twimg.com/profile_background_images/7904884343728/ab960e4a9bfeb7dd71c91e5b4f5c9dd1.jpeg', profile_link_color='C34242', id_str='44873543411', listed_count=2, notifications=False, following=True, _api=<tweepy.api.API object at 0x000000000327D828>, geo_enabled=False, location='LOCATION', default_profile=False, profile_use_background_image=True, favourites_count=19, profile_sidebar_fill_color='C9C9C9', lang='en', utc_offset=25200, friends_count=232, protected=False, has_extended_profile=False, profile_background_color='07090B', followers_count=2926, created_at=datetime.datetime(20309, 6, 5,3 11, 39, 26), contributors_enabled=False, profile_image_url_https='https://pbs.twimg.com/profile_images/3788003234000505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png', profile_banner_url='https://pbs.twimg.com/profile_banners/44873511/1359873943465', profile_background_tile=True, description='|DSECRIPTION|', profile_text_color='1C1F23', profile_sidebar_border_color='FFFFFF', is_translator=False, entities={'description': {'urls': []}}, is_translation_enabled=False, time_zone=,profile_background_image_url_https='https://pbs.twimg.com/profile_background_images/790488728/ab960e4a9bfeb7dd71c43491e5b4f5c9dd1.jpeg', follow_request_sent=False, name='Xxx Xxx', profile_image_url='http://pbs.twimg.com/profile_images/3788000563400505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png', url=None, default_profile_image=False), sender_screen_name='xxxtnb', sender_id=4487345511, sender_id_str='4487343511', text='kjbkljb', id=715904763565666629443, created_at=datetime.datetime(2016, 4, 1, 14, 12, 51), id_str='715904763565629443', recipient=User(statuses_count=8, verified=False, _json={'default_profile_image': False, 'statuses_count': 8, 'following': False, 'verified': False, 'entities': {'description': {'urls': []}}, 'profile_background_image_url': 'http://pbs.twimg.com/profile_background_images/2424565639181/KOJ.jpg', 'screen_name': 'xxxx', 'is_translation_enabled': False, 'id': 82332348693, 'id_str': '82232348693', 'notifications': False, 'name': 'Yyyyy yyyyy', 'profile_text_color': '0C3E53', 'profile_background_tile': False, 'location': xxxx', 'default_profile': False, 'profile_use_background_image': True, 'profile_sidebar_fill_color': 'FFF7CC', 'lang': 'en', 'protected': False, 'has_extended_profile': False, 'profile_background_color': 'BADxFCD', 'is_translator': False, 'created_at': xxx 2009', 'contributors_enabled': False, 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1302134054090532/36114_1220026641036_1840037693_409509_786157_n_normal.jpg', 'time_zone':, 'description': DESC.', 'listed_count': 0, 'profile_sidebar_border_color': 'F2E195', 'followers_count': 134, 'favourites_count': 0, 'geo_enabled': False, 'friends_count': 49, 'profile_background_image_url_https': 'https://pbs.twimg.com/profile_background_images/242439134381/KOJ.jpg', 'follow_request_sent': False, 'utc_offset': 19800, 'profile_image_url': 'http://pbs.twimg.com/profile_images/1302134032/36114_1220026641036_341840037693_409509_786157_n_normal.jpg', 'url': None, 'profile_link_color': 'FF0000'}, id=8234834693, screen_name='', profile_background_image_url='http://pbs.twimg.com/profile_background_images/2424343439181/KOJ.jpg', profile_link_color='FF0000', id_str='82348693', listed_count=0, notifications=False, following=False, _api=<tweepy.api.API object at 0x000000000327D828>, geo_enabled=False, location=’x', default_profile=False, profile_use_background_image=True, favourites_count=0, profile_sidebar_fill_color='FFF7CC', lang='en', utc_offset=194800, friends_count=494, protected=False, has_extended_profile=False, profile_background_color='BADFCD', followers_count=144, created_at=datetime.datetime(2009, 10, 14, 12, 36, 46), contributors_enabled=False, profile_image_url_https='https://pbs.twimg.com/profile_images/130213404332/4336114_1220026641036_1840037693_40943509_786157_n_normal.jpg', profile_background_tile=False, description=DESC.', profile_text_color='0C3E53', profile_sidebar_border_color='F2E195', is_translator=False, entities={'description': {'urls': []}}, is_translation_enabled=False, time_zone='’, profile_background_image_url_https='https://pbs.twimg.com/profile_background_images/242434434349181/KOJ.jpg', follow_request_sent=False, name='Yyyyy yyyyy', profile_image_url='http://pbs.twimg.com/profile_images/1302134032/36143414_1220026641036_1840037693_40954309_786157_n_normal.jpg', url=None, default_profile_image=False), recipient_id=8234348693, entities={'user_mentions': [], 'hashtags': [], 'urls': [], 'symbols': []}, 

我想在文本标记下获取从此发送的邮件内容。

1 个答案:

答案 0 :(得分:0)

这适合我。

gdb