I have a list of usernames in one column of the csv file. For example,
I'd like to read each line of username into the 'keyword' and achieve the tweets of each usernames by looping this process, and store those into "filename.csv". For example, I want to store result of '(from: @a') lang:en since:2017-05-07 until:2018-05-06 -filter:replies', '(from: @b') lang:en since:2017-05-07 until:2018-05-06 -filter:replies', '(from: @c') lang:en since:2017-05-07 until:2018-05-06 -filter:replies' in the for loop below by looping the process.
Could anyone help me how to do this?
import snscrape.modules.twitter as sntwitter import csv maxTweets = 500000 tweets = [] tdf = None #Open/create a file to append data to csvFile = open('history_antiaging_1007_test.csv', 'a', newline='', encoding='utf8') #Use csv writer csvWriter = csv.writer(csvFile) csvWriter.writerow(['username','date','link']) with open('list.txt') as f: for keyword in f: for i,tweet in enumerate(sntwitter.TwitterSearchScraper('(from: @' + keyword + ') lang:en since:2017-05-07 until:2018-05-06 -filter:replies').get_items()): if i > maxTweets : break csvWriter.writerow([tweet.username, tweet.date, tweet]) f.close csvFile.close() https://stackoverflow.com/questions/65605613/how-can-i-loop-process-of-reading-each-lines-of-list-in-python January 07, 2021 at 09:48AM
没有评论:
发表评论