JustAnotherArchivist / snscrape

A social networking service scraper in Python
GNU General Public License v3.0
4.5k stars 713 forks source link

AttributeError: module 'snscrape.modules.twitter' has no attribute 'TwitterProfileScraper' #458

Closed isaZuluaga closed 2 years ago

isaZuluaga commented 2 years ago

@xmainguyen I assume you're asking about using the profile scraper from a Python script (instead of the CLI).

import snscrape.modules.twitter.

for tweet in snscrape.modules.twitter.TwitterProfileScraper('username').get_items():
    # Do something with the tweet object, e.g.
    print(tweet.url)

Originally posted by @JustAnotherArchivist in https://github.com/JustAnotherArchivist/snscrape/issues/83#issuecomment-805467618

isaZuluaga commented 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():

Do something with the tweet object, e.g.

print(tweet.url)

AttributeError: module 'snscrape.modules.twitter' has no attribute 'TwitterProfileScraper'

Does anyone know how to solve it?

JustAnotherArchivist commented 2 years ago

What are your Python and snscrape versions?

isaZuluaga commented 2 years ago

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

JustAnotherArchivist commented 2 years ago

That's an ancient version of snscrape. You'll need Python 3.8+ for the newer ones that have the profile scraper.

isaZuluaga commented 2 years ago

I see , thank you so much for the fast respond :)

Reedheyner commented 2 years ago

Hello! Please! I got an error when trying to run snscrape.modules.twitte on Python 3.10.6. Please! can you help?

Best

Reedheyner commented 2 years ago

Hello! Please! I got an error when trying to run snscrape.modules.twitter on Python 3.10.6. Please! can you help?

Best

TheTechRobo commented 2 years ago

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.

Reedheyner commented 2 years ago
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
Reedheyner commented 2 years ago
[{
    "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
}]
Reedheyner commented 2 years ago

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')
TheTechRobo commented 2 years ago

You haven't installed snscrape correctly.

Reedheyner commented 2 years ago

Please! How should I install?

Reedheyner commented 2 years ago

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
}]
Reedheyner commented 2 years ago

The pandas are missing : Import "pandas" could not be resolved from source"

Reedheyner commented 2 years ago

I am using Python 3.10.6

JustAnotherArchivist commented 2 years ago

None of this has anything to do with the original issue here. Your setup is just thoroughly broken.

Reedheyner commented 2 years ago

Hello! Please! can you help with the snscrap.modules.twitter ?**** installation?

Reedheyner commented 2 years ago

Hello! Are you there? What should I do?

TheTechRobo commented 2 years ago

None of this has anything to do with the original issue here. Your setup is just thoroughly broken.

Reedheyner commented 2 years ago

ok. Does it mean I have to uninstall my visual studio or python and install them again?

Reedheyner commented 2 years ago

Your script is brilliant and I know you are the only one that can help me to run it. Please! help!

JustAnotherArchivist commented 2 years ago

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.

Subhan-Zaheer commented 1 year ago
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 ?

JustAnotherArchivist commented 1 year ago

@Subhan-Zaheer By not typoing 'Scraper'. There's only one 'p' in it.

Subhan-Zaheer commented 1 year ago

@Subhan-Zaheer By not typoing 'Scraper'. There's only one 'p' in it.

Thanks @JustAnotherArchivist issue is resolved...

Akshata2421 commented 3 months ago

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 for i,tweet in enumerate(sntwitter.TwitterSearchScraper('from:jack').get_items()): AttributeError: module 'snscrape' has no attribute 'TwitterSearchScraper'

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