简体   繁体   中英

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)

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.

#!/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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM