diff --git a/twitterscraper/tweet.py b/twitterscraper/tweet.py index cad43fa..6d2829f 100644 --- a/twitterscraper/tweet.py +++ b/twitterscraper/tweet.py @@ -17,27 +17,34 @@ def __init__(self, user, fullname, id, url, timestamp, text, replies, retweets, self.retweets = retweets self.likes = likes self.html = html + self.mentions = mentions @classmethod def from_soup(cls, tweet): + mentions = [] + try: + mentions = tweet.find('div', 'tweet')['data-mentions'].split() + except e: + pass return cls( user=tweet.find('span', 'username').text[1:], fullname=tweet.find('strong', 'fullname').text, id=tweet['data-item-id'], - url = tweet.find('div', 'tweet')['data-permalink-path'], + url=tweet.find('div', 'tweet')['data-permalink-path'], timestamp=datetime.utcfromtimestamp( int(tweet.find('span', '_timestamp')['data-time'])), text=tweet.find('p', 'tweet-text').text or "", - replies = tweet.find( + replies=tweet.find( 'span', 'ProfileTweet-action--reply u-hiddenVisually').find( 'span', 'ProfileTweet-actionCount')['data-tweet-stat-count'] or '0', - retweets = tweet.find( + retweets=tweet.find( 'span', 'ProfileTweet-action--retweet u-hiddenVisually').find( 'span', 'ProfileTweet-actionCount')['data-tweet-stat-count'] or '0', - likes = tweet.find( + likes=tweet.find( 'span', 'ProfileTweet-action--favorite u-hiddenVisually').find( 'span', 'ProfileTweet-actionCount')['data-tweet-stat-count'] or '0', html=str(tweet.find('p', 'tweet-text')) or "", + mentions=mentions, ) @classmethod