我想在特定的时间范围内从twitter中提取推文。代码
import tweepy
import csv
from tweepy import OAuthHandler
consumer_key = ''
consumer_secret = ''
access_token = ''
access_secret = ''
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
#csvFile=open('tweets.csv','a')
#csvWriter=csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,
q="#tatamotors",
lang="en",
since="2016-01-12",
until="2016-06-07").items():
print (tweet.created_at, tweet.text)
#csvWriter.writerow([tweet.created_at,tweet.text.encode('utf-8')])
我得到 - “名称错误:名称api未定义”
答案 0 :(得分:1)
您在调用api
之前错过了一行,首先使用此构建api
:
api = tweepy.API(auth)