我正在编写机器人程序,我需要搜索记录的趋势。但是返回的搜索结果只是[],也就是什么。这是代码的粘贴框。 https://pastebin.com/pkJ2McUq和一个代码段。
import tweepy
APIKey=input("API Key, Please.\n")
APIKeysecret=input("And To Confirm, Your Secret Api Key.\n")
AccessToken=input("Your Access Token?\n")
AccessTokenSecret=input("And The Secret Token.\n")
auth = tweepy.OAuthHandler(APIKey, APIKeysecret)
auth.set_access_token(AccessToken, AccessTokenSecret)
with open("TrendsResult/atrendsresults.json", 'w') as atrendssearchresults :
print(api.search('IndividualTrends/0.txt', lang="EN", result_type = "popular"), file=atrendssearchresults)
with open("TrendsResult/btrendsresults.json", 'w') as btrendssearchresults :
print(api.search('IndividualTrends/1.txt', lang="EN", result_type = "popular"), file=btrendssearchresults)
with open("TrendsResult/ctrendsresults.json", 'w') as ctrendssearchresults :
print(api.search('IndividualTrends/2.txt', lang="EN", result_type = "popular"), file=ctrendssearchresults)
with open("TrendsResult/dtrendsresults.json", 'w') as dtrendssearchresults :
print(api.search('IndividualTrends/3.txt', lang="EN", result_type = "popular"), file=dtrendssearchresults)
with open("TrendsResult/etrendsresults.json", 'w') as etrendssearchresults :
print(api.search('IndividualTrends/4.txt', lang="EN", result_type = "popular"), file=etrendssearchresults)
with open("TrendsResult/ftrendsresults.json", 'w') as ftrendssearchresults :
print(api.search('IndividualTrends/5.txt', lang="EN", result_type = "popular"), file=ftrendssearchresults)
with open("TrendsResult/gtrendsresults.json", 'w') as gtrendssearchresults :
print(api.search('IndividualTrends/6.txt', lang="EN", result_type = "popular"), file=gtrendssearchresults)
with open("TrendsResult/htrendsresults.json", 'w') as htrendssearchresults :
print(api.search('IndividualTrends/7.txt', lang="EN", result_type = "popular"), file=htrendssearchresults)
with open("TrendsResult/itrendsresults.json", 'w') as itrendssearchresults :
print(api.search('IndividualTrends/8.txt', lang="EN", result_type = "popular"), file=itrendssearchresults)
with open("TrendsResult/jtrendsresults.json", 'w') as jtrendssearchresults :
print(api.search('IndividualTrends/j.txt', lang="EN", result_type = "popular"), file=jtrendssearchresults)
我该如何解决?
这些搜索均不会返回任何结果,因为没有与这些查询匹配的推文。您正在搜索字符串本身,而不是它们引用的文件中的任何内容。另外,您应该研究使用循环。