python发起http请求,并解析返回的json字符串的小demo,方便以后用到。
#! /usr/bin/env python # -*- coding:gbk -*- import os import sys import json import urllib import urllib2 if __name__ == "__main__": query_file = sys.argv[1] query_index = 0 with open(query_file, 'r') as fp: for line in fp: query = line.rstrip() query_index = query_index + 1 query_gbk = query query = query.decode('gbk', 'ignore').encode('utf8', 'ignore') url = 'http://10.42.141.12:8089/adrender"Content-Type" content="text/html; charset=UTF-8">\<head>\') output.write("%s" % (ad)) output.write('\</html>\') output.close()
以上这篇Python发送http请求解析返回json的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。