问题描述
我正在使用 Tweepy,但似乎没有办法从用户的特定推文中获取评论数量.我可以使用 tweet.favorite_count
和 tweet.retweet_count
来获取收藏和转发,但我正在寻找一种方法来获取对该帖子的评论数量.我什至不需要看评论是什么.只是数量.谢谢!
I am using Tweepy and it does not seem like there is a way to scrape the number of comments on a particular tweet from a user. I can use the tweet.favorite_count
and tweet.retweet_count
to get favorites and retweets but I am looking for a way to get the number of comments on that post. I don't even need to see what the comments are. Just the quantity. Thanks!
推荐答案
我相信你的意思是回复.无论如何,您所要做的就是仔细检查页面源代码(CTRL+F 并搜索回复"),这样您就可以知道稍后要在 BeautifulSoup
对象中查找什么:
I believe you meant replies. Anyway, all you have to do is carefully inspect the page source (CTRL+F and search for "replies"), so you can know what to look for in a BeautifulSoup
object later on:
import requests
from bs4 import BeautifulSoup
html = requests.get('https://twitter.com/Cristiano/status/912028229011169281')
soup = BeautifulSoup(html.text, 'lxml')
comments = soup.find_all('span', attrs={'class':'ProfileTweet-actionCountForAria'})[0].contents
print(*comments)
...输出:
9,370 条回复
这篇关于有没有办法使用python获取推文的评论数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!