如何提取推文并将其存储在 CSV 文件中?
How to extract tweet and store it in CSV file?
我写了这段代码来保存我从特定用户提取的 id
和 tweet
但问题是它只保存索引为 50 的第一条推文 我尝试计数器但没有任何反应。
a=50
for info in tweets[:a]:
with open(userID+'.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["id", "tweet"])
writer.writerow([info.id,info.full_text+ "\n"])
a-=1
使用附加模式而不是写入。
with open(userID+'.csv', 'a', newline='') as file:
'w' : 写模式实际上是替换已有的内容。 'a' :追加模式向现有文件添加数据。
在这里阅读:
https://www.guru99.com/reading-and-writing-files-in-python.html
我写了这段代码来保存我从特定用户提取的 id
和 tweet
但问题是它只保存索引为 50 的第一条推文 我尝试计数器但没有任何反应。
a=50
for info in tweets[:a]:
with open(userID+'.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["id", "tweet"])
writer.writerow([info.id,info.full_text+ "\n"])
a-=1
使用附加模式而不是写入。
with open(userID+'.csv', 'a', newline='') as file:
'w' : 写模式实际上是替换已有的内容。 'a' :追加模式向现有文件添加数据。 在这里阅读: https://www.guru99.com/reading-and-writing-files-in-python.html