Why am I getting this error on the snscrape? I have updated the python and the snscrape in the real time, both are updated.
PS C:UsersmuzamOneDriveDesktopSummerproject 1> python -u "c:UsersmuzamOneDriveDesktopSummerproject 1Daraz Sentiment AnalysistempCodeRunnerFile.py"
Traceback (most recent call last):
File "c:UsersmuzamOneDriveDesktopSummerproject 1Daraz Sentiment AnalysistempCodeRunnerFile.py", line 1, in <module>
import snscrape.modules.twitter as sntwitter
File "C:UsersmuzamAppDataLocalProgramsPythonPython312Libsite-packagessnscrapemodules__init__.py", line 17, in <module>
_import_modules()
File "C:UsersmuzamAppDataLocalProgramsPythonPython312Libsite-packagessnscrapemodules__init__.py", line 13, in _import_modules
module = importer.find_module(moduleName).load_module(moduleName)
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'FileFinder' object has no attribute 'find_module'`
My code for this error:
import snscrape.modules.twitter as sntwitter
import csv
def is_english_textual_tweet(tweet):
return (
tweet.lang == 'en' and
not tweet.retweetedTweet and
not tweet.inReplyToTweetId and
not tweet.media
)
username = 'nfak_ism_'
tweets = []
for tweet in sntwitter.TwitterSearchScraper(f'from:{username}').get_items():
if is_english_textual_tweet(tweet):
tweets.append({
'date': tweet.date.strftime('%Y-%m-%d %H:%M:%S'),
'content': tweet.content,
'id': tweet.id,
'username': tweet.user.username
})
csv_file = 'tweets.csv'
with open(csv_file, mode='w', newline='', encoding='utf-8') as file:
writer = csv.DictWriter(file, fieldnames=['date', 'content', 'id', 'username'])
writer.writeheader()
writer.writerows(tweets)
print(f'Scraped {len(tweets)} tweets from @{username}')
import pandas as pd
df = pd.read_csv(csv_file)
print(df.head(3))
New contributor
Muzamil Haider is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.