Как устранить эту ошибку Python SnscrapePython

Программы на Python
Anonymous
Как устранить эту ошибку Python Snscrape

Сообщение Anonymous »

Почему я получаю эту ошибку в snscrape? Я обновил Python и snscrape в режиме реального времени, оба обновлены.
PS C:\Users\muzam\OneDrive\Desktop\Summer\project 1> python -u "c:\Users\muzam\OneDrive\Desktop\Summer\project 1\Daraz Sentiment Analysis\tempCodeRunnerFile.py"
Traceback (most recent call last):
File "c:\Users\muzam\OneDrive\Desktop\Summer\project 1\Daraz Sentiment Analysis\tempCodeRunnerFile.py", line 1, in
import snscrape.modules.twitter as sntwitter
File "C:\Users\muzam\AppData\Local\Programs\Python\Python312\Lib\site-packages\snscrape\modules\__init__.py", line 17, in
_import_modules()
File "C:\Users\muzam\AppData\Local\Programs\Python\Python312\Lib\site-packages\snscrape\modules\__init__.py", line 13, in _import_modules
module = importer.find_module(moduleName).load_module(moduleName)
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'FileFinder' object has no attribute 'find_module'`

Мой код этой ошибки:
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))



Подробнее здесь: https://stackoverflow.com/questions/786 ... rape-error

Вернуться в «Python»