简体   繁体   English

如何使每条推文都在自己的行上?

[英]How to make each tweet on its own line?

I am wanting to have each tweet be on its own line. 我想让每条推文都在自己的路线上。

Currently, this breaks at each response (I listed Response_1...I am using through Response_10) 目前,每个响应都会中断(我列出了Response_1 ......我通过Response_10使用)

Any ideas? 有任何想法吗?

#!/usr/bin/env python

import urllib
import json

response_1 = urllib.urlopen("http://search.twitter.com/search.json?q=microsoft&page=1")
for i in response_1:
    print (i, "\n")

You have to parse the json as a python object first, only then you can iterate over it. 您必须首先将json解析为python对象,然后才能迭代它。

#!/usr/bin/env python                                                                                              

import urllib
import json

response_1 = json.loads(urllib.urlopen("http://search.twitter.com/search.json?q=microsoft&page=1").read())
for i in response_1['results']:
    print (i, "\n")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使文本文件中的每一行都有自己的字典,以便在 Python 中进行排序? - How do I make each line in a text file its own dictionary to sort through in Python? 如何在自己的单独行上进行函数循环? - How to make function loop on its own separate line? 在 Pygame 中用自己的碰撞将一条线作为精灵 - Make a line as a sprite with its own collision in Pygame 如何附加循环的输出而不是使每个循环成为自己的行 - How to append an output that is looping rather than making each loop its own line 如何在 Python 中将文本文件(每个单独的项目在自己的行上)读入 2D 列表 - How to read a text file (each individual item on its own line) into a 2D list in Python 如何使用 Python 请求在自己的行上发送带有每个有效负载的 POST 请求 - How to send POST request with each payload on its own line using Python requests 如何给每个 URL 自己的线程 - How to give each URL its own threading 如何制作每个键都有自己颜色的键盘图 - How to make a figure of a keyboard where each key has its own color 如何将列表写入csv,并使列表中的每个元素成为其自己的列? - How do I write a list to a csv and make each element in the list be its own column? 如何在Python 2.7.2中获取一串数字并使每个数字成为列表中自己的元素? - How do I take a string of numbers in Python 2.7.2 and make each number its own element in a list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM