我的代码
#!/usr/bin/python
import tweepy
import csv #Import csv
auth = tweepy.auth.OAuthHandler('XXXXXX', 'XXXXXXX')
auth.set_access_token('XXX-XXX', 'XXX')
api = tweepy.API(auth)
# Open/create a file to append data to
csvFile = open('result.csv', 'a')
#Use csv writer
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,
q = "google",
since = "2014-02-14",
until = "2014-02-15",
lang = "en").items():
# Write a row to the CSV file. I use encode UTF-8
csvWriter.writerow([tweet.created_at,tweet.user, tweet.text.encode('utf-8')])
print tweet.created_at, tweet.text
csvFile.close()
这里我无法在输出中获得user_id。 输出是
2018-04-24 10:54:34转发@BoldContentTV:非常高兴能够首次亮相@StylistMagazine和。拥有才华横溢的@ericafmstyle,#Fashi ......
是什么原因?以及如何获取用户ID?我想要三个方面的日期/用户ID /文本。
我收到了代码from
答案 0 :(得分:1)
你可以得到,
用户名:tweet.user.screen_name
文字为:tweet.text
created_at:tweet.created_at
示例代码:
In [33]: import tweepy
In [34]: auth = tweepy.OAuthHandler('', '')
In [35]: auth.set_access_token('', '')
In [36]: api = tweepy.API(auth)
In [37]: for tweet in tweepy.Cursor(api.search, q = "nishant").items(5):
...: print tweet.user.screen_name , tweet.text, tweet.created_at
...:
GuruInAJeans RT @periferrydotcom: Shaina's story is all about courage and the will to achieve.
it shows how patience can go a long way.
Full Story: htt… 2018-04-24 13:02:42
bajjiladeva @ts_nishant @KTRTRS neku ikkada first nene chepta bro inauguration date .. 2018-04-24 12:57:37
ts_nishant Don’t @KTRTRS <twitter short url> 2018-04-24 12:55:43
ts_nishant When @KTRTRS ?? <twitter short url> 2018-04-24 12:55:13
parivesh100 Nishant Shah on the invisible environmental costs that the digital age has brought - <twitter short url> 2018-04-24 12:47:56