mahrtayyab / tweety

Twitter Scraper
494 stars 67 forks source link

How can we get all the comments on a post ? #192

Closed Rgwww closed 1 day ago

Rgwww commented 5 months ago

I'm using your project interface to get comment data from a user's post, But when I use the app.get_tweet_comments method, getting the comments doesn't match what I get on the page. app.get_tweet_comments("1798731573723815974", 1, cursor = 'PAAAAPAtPBwcFr7E1vGNnr32MRUCAAAYJmNvbnZlcnNhdGlvbnRocmVhZC0xNzk4NzQ3MDk4MTU1OTgzMjc0IgAA', get_hidden = True) I read the documentation and couldn't find a way to fix it,

5e6d3ba2b29e265971f8c4217b6626a 206ef62a7e4ac089db5b15dee7364c7
mahrtayyab commented 5 months ago

get_tweet_comments return TweetComments object, has attribute tweets which are basically the list of ConversationThread.

Iterating over this list will give you ConversationThread objects has attribute of tweets which are the list of Tweets

Iterating over ConversationThread will give you Tweet object. On this object you get text attribute to get the text.


comments = client.get_tweet_comments("1798731573723815974", 1, get_hidden=True)
for _thread in comments:
    print(_thread) # This is ConversationThread
    for comment in _thread:
        print(comment) # This is Tweet
        print(comment.text)
        print(comment.media)
Rgwww commented 5 months ago

get_tweet_comments返回TweetComments对象,其属性tweets基本上是 ConversationThread 的列表。

迭代此列表将为你提供ConversationThread对象tweets,该对象具有 Tweets 列表的属性

迭代 ConversationThread 将为您提供Tweet对象。在此对象上,您可以获得text属性来获取文本。

comments = client.get_tweet_comments("1798731573723815974", 1, get_hidden=True)
for _thread in comments:
    print(_thread) # This is ConversationThread
    for comment in _thread:
        print(comment) # This is Tweet
        print(comment.text)
        print(comment.media)

Just like this post, there are 3 comments in the web post of tweets[0], and only 2 comments in the iterative access. Although there is a cursor, I also tried to use the cursor to obtain the third comment, but it still couldn't be obtained. Is it that the api of this project can't support more levels of comment data

mahrtayyab commented 5 months ago

You can call .expand() method on ConversationThread if you want to get all tweets of that thread

Rgwww commented 5 months ago

I'll try again. Thank you very much