【发布时间】:2021-06-16 11:59:46
【问题描述】:
所以我想知道人们对肯德基、大力水手和 ChickfilA 的鸡肉三明治的看法。注意:我已经拥有我需要的所有 Twitter 数据。
我成功提取了用户和他们的昵称,但还没有弄清楚如何更进一步,找出谁在他们的推文中提到了“三明治”。
我很确定这段代码所做的是提取所有推文完全是“三明治”的用户......我不知道如何提取刚刚提到三明治的推文。我已经研究并认为我可以使用 re.findall() 或 Tweepy 库来完成这项任务?谁能告诉我我需要做什么?
这是我迄今为止尝试过的:
uniqueusers = {}
keyword = 'sandwich'
for tweetzipfile in tweetzipfiles:
zf = zipfile.ZipFile(tweetzipfile)
for i, obj in enumerate(zf.infolist()):
tweetjson = json.load(zf.open(obj))
userwhotweeted = tweetjson['user']['screen_name']
tweettext = tweetjson['text']
if tweettext == keyword:
if userwhotweeted in uniqueusers:
uniqueusers[userwhotweeted] += 1
if userwhotweeted not in uniqueusers:
uniqueusers[userwhotweeted] = 1
【问题讨论】:
-
将
if tweettext == keyword:更改为if keyword in tweettext:
标签: python json dictionary twitter text-extraction