Python Tweepy Execution Questions

Asked 2 years ago, Updated 2 years ago, 74 views

I want to crawl the contents of Twitter with Python I don't think the Tweepy package is running, what should I do? TT

(May I know the maximum collection limit for Twitter?)

The code is as follows

import tweepy


consumer_key = "DUtpRNHpSEFhVj1dJ890cLIya"
consumer_secret = "08CA1vAGuZWHsbQUovqxqOBuicw44fLxalNE8TLDHTiDNoyIfb"
access_token = "908202087032352768-WuZtPZDBubODjEuND1QawgpDPcVioEc"
access_token_secret = "OrTedtrPE0zlu4JdcmLuGpjZjw3okYqFMwGwrci9uJzoF"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)


location = "%s,%s,%s" % ("35.95", "128.25", "1000 km") # search criteria (central Korea) coordinates, radius
Keyword = "Small but certain happiness"
wfile = open(os.getcwd()+"/twitter.txt", mode='w')

cursor = tweepy.Cursor(api.search,
                       q=keyword,
                       Tweets written after 'since='2016-01-01', #2015-01-01 are imported
                       count=100, #Twitter to return per page up to 100
                       geocode=location,
                       include_entities=True)

for i, tweet in enumerate(cursor.items()):
    print("{}: {}".format(i, tweet.text))
    wfile.write(tweet.text + '\n')
wfile.close()

crawling

2022-09-22 18:12

1 Answers

I came across it while working on a team project (Of course, you've already solved it by now...)LOL) I'm just going to post a solution in case other people experience this problem.

You can see that the file is named tweepy.py Due to the Python nature, this will attempt to import itself instead of the tweepy library.

Change the file name so that it does not overlap with other libraries, and try running it again again. :)

Additionally, all information on collection restrictions and more can be found at the following URL: https://developer.twitter.com


2022-09-22 18:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.