python http get请求返回json字符串

# -*- coding: UTF-8 -*-

import urllib
import urllib2
import time
import sys

reload(sys)


url = 'http://77tj.org/api/tencent/onlineim'
headers = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}


while True:
    req = urllib2.Request(url=url, headers=headers)
    res_data = urllib2.urlopen(req)
    res = res_data.read()
    print res
    # print(u'\033[0;36m床前明月光,')
    # print(u'疑是地上霜。')
    # print(u'举头望明月,')
    # print(u'低头思故乡。\033[0m')
    #
    # concent = u"请输入内容:"

    # print concent

你可能感兴趣的:(6.python技术杂谈)