Closed isaZuluaga closed 2 years ago
Hi, I am new using snscrape, I am trying to implement this example to use the profile scraper from a Python script, but i am getting the following error:
import snscrape.modules.twitter as sntwitter
for tweet in sntwitter.TwitterProfileScraper('HillaryClinton').get_items():
print(tweet.url)
AttributeError: module 'snscrape.modules.twitter' has no attribute 'TwitterProfileScraper'
Does anyone know how to solve it?
What are your Python and snscrape versions?
i am using !pip3 install snscrape to install the library. this is the version that i have:
Python implementation: CPython Python version : 3.7.13 IPython version : 5.5.0
numpy : 1.21.5 pandas : 1.3.5 requests: 2.23.0 snscrape: 0.3.4
That's an ancient version of snscrape. You'll need Python 3.8+ for the newer ones that have the profile scraper.
I see , thank you so much for the fast respond :)
Hello! Please! I got an error when trying to run snscrape.modules.twitte on Python 3.10.6. Please! can you help?
Best
Hello! Please! I got an error when trying to run snscrape.modules.twitter on Python 3.10.6. Please! can you help?
Best
Please! I got an error when trying to run snscrape.modules.twitte on Python 3.10.6. Please! can you help?
Please file a new issue with a description of the error and the traceback.
At line:9 char:4
+ for tweet in sntwitter.TwitterSearchScraper(query).get_items():
+ ~
Missing opening '(' after keyword 'for'.
At line:13 char:7
+ if len(tweets) == limit:
+ ~
Missing '(' after 'if' in if statement.
At line:18 char:25
+ df = pd.DataFrame(tweets, columns=['Date', 'User', 'Tweet'])
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword
[{
"resource": "/C:/Python310/Retweet.py",
"owner": "_generated_diagnostic_collection_name_#0",
"code": {
"value": "reportMissingImports",
"target": {
"$mid": 1,
"external": "https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules",
"path": "/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md",
"scheme": "https",
"authority": "github.com",
"fragment": "diagnostic-severity-rules"
}
},
"severity": 4,
"message": "Import \"snscrape.modules.twitter\" could not be resolved",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 8,
"endLineNumber": 1,
"endColumn": 32
}]
The big problem is the message "snscrape.modules.twitter" could not be resolved", I have used the raw lines below provided without modification
import snscrape.modules.twitter as sntwitter
import pandas as pd
query = "(from:elonmusk) until:2020-01-01 since:2010-01-01"
tweets = []
limit = 5000
for tweet in sntwitter.TwitterSearchScraper(query).get_items():
# print(vars(tweet))
# break
if len(tweets) == limit:
break
else:
tweets.append([tweet.date, tweet.username, tweet.content])
df = pd.DataFrame(tweets, columns=['Date', 'User', 'Tweet'])
print(df)
# to save to csv
# df.to_csv('tweets.csv')
You haven't installed snscrape correctly.
Please! How should I install?
This message also is strange
[{
"resource": "/C:/Python310/Retweet.py",
"owner": "_generated_diagnostic_collection_name_#0",
"code": {
"value": "reportMissingModuleSource",
"target": {
"$mid": 1,
"external": "https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules",
"path": "/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md",
"scheme": "https",
"authority": "github.com",
"fragment": "diagnostic-severity-rules"
}
},
"severity": 4,
"message": "Import \"pandas\" could not be resolved from source",
"source": "Pylance",
"startLineNumber": 2,
"startColumn": 8,
"endLineNumber": 2,
"endColumn": 14
}]
The pandas are missing : Import "pandas" could not be resolved from source"
I am using Python 3.10.6
None of this has anything to do with the original issue here. Your setup is just thoroughly broken.
Hello! Please! can you help with the snscrap.modules.twitter ?**** installation?
Hello! Are you there? What should I do?
None of this has anything to do with the original issue here. Your setup is just thoroughly broken.
ok. Does it mean I have to uninstall my visual studio or python and install them again?
Your script is brilliant and I know you are the only one that can help me to run it. Please! help!
I don't know what the problem with your installation is. Maybe you can find guides on the web about setting things up correctly with that (fairly common) combination of operating system and software environment. Or search on the Python forums. In any case, please stop spamming here as this is not related to snscrape.
for i, tweet in enumerate(sntwitter.TwitterSearchScrapper(f'{keywords} lang:{language} near:{location} ').get_items()):
if i >100:
break
print(tweet.user.username, tweet.content)
i have written this code but i am getting the error :
AttributeError Traceback (most recent call last)
Cell In[7], line 1
----> 1 for i, tweet in enumerate(sntwitter.TwitterSearchScrapper(f'{keywords} lang:{language} near:{location} ').get_items()):
2 if i >100:
3 break
File D:\Softwares\Anaconda running\lib\site-packages\snscrape\utils.py:38, in module_deprecation_helper.<locals>.__getattr__(name)
36 warnings.warn(f'{name} is deprecated, use {names[name].__name__} instead', DeprecatedFeatureWarning, stacklevel = 2)
37 return names[name]
---> 38 raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
AttributeError: module 'snscrape.utils' has no attribute 'TwitterSearchScrapper'
snscrape version i'm using is : 0.7.0.20230622 version of python i'm using is : Python 3.10.11 how to solve the issue ?
@Subhan-Zaheer By not typoing 'Scraper'. There's only one 'p' in it.
@Subhan-Zaheer By not typoing 'Scraper'. There's only one 'p' in it.
Thanks @JustAnotherArchivist issue is resolved...
I am getting this error, kindly guide me in fixing this issue:
C:\Users\Admin>python dcp.py
Traceback (most recent call last):
File "C:\Users\Admin\dcp.py", line 16, in
I am using Python and Snscrape versions given below: Python 3.9.12 snscrape 0.7.0.20230622 I have also set the path and the classpath environment variables to the path where "snscrape.exe" is installed
@xmainguyen I assume you're asking about using the profile scraper from a Python script (instead of the CLI).
Originally posted by @JustAnotherArchivist in https://github.com/JustAnotherArchivist/snscrape/issues/83#issuecomment-805467618