linux - 如何为推特获取信息?

标签 linux grep

如果我有以下输入,我想得到输出“tester123”:

[{"id":4133554,"id_str":"445444","name":"tester123","screen_name":"whatelse"}]

用 grep 命令可以吗?

最佳答案

我知道你说的是 grep,但你的输入显然是 JSON,grep 并没有真正解析它。您可以使用快速的 Python 解决方案:

import json
inText = '[{"id":4133554,"id_str":"445444","name":"tester123","screen_name":"whatelse"}]'
data = json.loads(inText)
print data[0]['name']

您可以根据您的输入格式以其他方式获得输入。例如,通过从文件读取或通过标准输入:

# Input file
with open('file.json') as fp:
     inText = fp.read()
# stdin
inText = raw_input()

关于linux - 如何为推特获取信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39007584/

相关文章:

javascript - 替换 linux tail -f 命令中的换行符

python - 在自己的 Ubuntu 服务器上部署 Flask 应用程序错误

regex - 匹配特定长度的单词,锚定,不做魔法数学

linux - 如何计算具有特定条目的文件数?

linux - 删除重复的 shell 命令

linux - 一起使用 find、grep 和 sed

regex - Mac 地址的 Grep 正则表达式

bash - 匹配单词列表中的单词并计算出现次数

linux - 什么是英特尔微码?

regex - grep -f 的性能问题