Home > Net >  How to fix 'Tweet' object has no attribute 'retweetCount'
How to fix 'Tweet' object has no attribute 'retweetCount'

Time:11-14

Using snscrape for this example. With python 3.8 and snscrape 0.3.4

import snscrape.modules.twitter as sntwitter

keyword = '(COVID19)'

tdf = None

for i, tweet in enumerate(sntwitter.TwitterSearchScraper(keyword ' since:2021-08-01 lang:pt').get_items()) :

if i >50:
    break
print(tweet.date.date())
print(tweet.retweetCount)    
print(tweet.renderedContent)

I get this : AttributeError: 'Tweet' object has no attribute 'retweetCount'

Thanks for your help.

CodePudding user response:

There is no Tweet.retweetCount in snscrape 0.3.4 — https://github.com/JustAnotherArchivist/snscrape/blob/v0.3.4/snscrape/modules/twitter.py

Update to the mainline, which adds many more Tweet properties — https://github.com/JustAnotherArchivist/snscrape/blob/master/snscrape/modules/twitter.py

YMMV.

CodePudding user response:

It's a problem with snscrape's version (0.3.4). After installing the development version (that is, 0.3.5.dev138 ga6b6f3f now) your code works.

To install the development version, use the command below (copy-paste from here):

$ pip3 install git https://github.com/JustAnotherArchivist/snscrape.git
...
$ pip3 list | grep snscrape
snscrape                          0.3.5.dev138 ga6b6f3f
  • Related