【发布时间】:2021-12-02 03:47:03
【问题描述】:
有没有办法用 python 对 Twitter 帖子发表评论?那么有没有图书馆可以做到这一点? 比如你把帖子中的链接放在哪里,以及要发送的评论。 提前谢谢!!!
【问题讨论】:
标签: python python-3.x twitter social-media
有没有办法用 python 对 Twitter 帖子发表评论?那么有没有图书馆可以做到这一点? 比如你把帖子中的链接放在哪里,以及要发送的评论。 提前谢谢!!!
【问题讨论】:
标签: python python-3.x twitter social-media
您可以创建一个可能能够对帖子发表评论的 Twitter 机器人,有许多机器人示例可以从新闻网站发表评论或在 Twitter 上发布新闻的 sn-p。我不认为有一个多合一的库可以做到这一点,但您可以使用这些库在 python 中构建自己的机器人。
beautifulsoup4==4.4.1
bs4==0.0.1
lxml==3.6.0
nltk==3.2.1
oauthlib==1.0.3
Pillow==3.2.0
requests==2.9.1
requests-oauthlib==0.6.1
simplejson==3.8.2
six==1.10.0
tweepy==3.5.0
Twython
以下程序将帮助您自动发布所有回复。它有一个延迟,因此 Twitter 不会将您的帐户标记为垃圾邮件。您需要身份验证和 Twitter id [不是您的] 来告诉机器人它必须在哪里发表评论。
id = str(id)
if id in ids_replied_to:
print('')
print('Skipped as already replied to')
print('')
print('')
else:
twitter_handle = '@' + screen_name
message = twitter_handle + " " + random.choice(rand_message)
twitter.update_status(status=message, in_reply_to_status_id=id)
print("Tweeted: %s" % message)
id = int(id)
ids_replied_to.append(id)
with open('ids_replied_to.txt', 'w') as filehandle:
filehandle.writelines("%s\n" % place for place in ids_replied_to)
# delay so that it doesn't look like the program is spamming Twitter
time.sleep(5)
【讨论】:
您可以使用 tweepy 库,并使用 update_status 函数回复推文。
使用 @ 提及用户,并使用推文 ID。
reply = api.update_status("Hello world to @username", tweet.id)
【讨论】: