📜  Python Tweepy – 获取推文的文本

📅  最后修改于: 2022-05-13 01:54:27.185000             🧑  作者: Mango

Python Tweepy – 获取推文的文本

在本文中,我们将了解如何获取状态/推文的文本。一条推文最多只能有 280 个字符。 Status 对象的 text 属性为我们提供了状态的文本。

在 GUI 中识别状态文本:

在上述状态中,状态文本为:

A programmer’s takeaway from the pandemic: Local variables over Global variables.

 What do you think?
.
.
.
.
.
#programming #coding  #programmingmemes #Covid_19 #codinglife #Python #javascript 
#pandemic #thursdayvibes

示例 1:考虑以下状态:

我们将使用状态 ID 来获取状态。上述状态的状态 ID 为 1272771459249844224。

# import the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# the ID of the status
id = 1272771459249844224
  
# fetching the status
status = api.get_status(id)
  
# fetching the text attribute
text = status.text 
  
print("The text of the status is : \n\n" + text)

输出 :

The text of the status is : 

Which movie did you watch recently?

Reply us!
.
.
.
.
.
#tuesdaymood #TuesdayThoughts #Bollywood #Hollywood #genre 
#movies #movie #fun

示例 2:考虑以下状态:

我们将使用状态 ID 来获取状态。上述状态的状态 ID 是 1272479136133627905。这次我们将获取状态的完整文本。在使用get_status()方法时,还将tweet_mode = "extended"作为参数传递。然后使用 full_text 属性获取完整的文本。

# the ID of the status
id = 1272479136133627905
  
# fetching the status with extended tweet_mode
status = api.get_status(id, tweet_mode = "extended")
  
# fetching the full_text attribute
full_text = status.full_text 
  
print("The text of the status is : \n\n" + full_text)

输出 :

The text of the status is : 

"I am thankful to programming for _______________."

Reply us most quirky/unexpected answers!
.
.
.
.
.
.
.
#coding #programming #codinglife #code #javascript #NodeJS  #reactjs #100DaysOfCode #codingisfun