Python发送http请求解析返回json小demo
来源:互联网 发布:黄瓜什么意思网络用语 编辑:程序博客网 时间:2024/05/21 19:28
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?query=%s&ad_num=3&srcid=101'\\ '&ip=172.22.182.55&baiduid=61ABB404320C72436EB6B8352DFBB388:FG=1' % (query) req = urllib2.urlopen(url) page = req.read() ddict = json.loads(page) expid = ddict['expid'] sid = ddict['sid'] ad_num = ddict['response_adnum'] for i in range(0, ad_num): output_html = '%s-%d.html' % (query_gbk, i) output = open(output_html, 'w') ad = ddict['response_ads'][i].encode('utf8', 'ignore') output.write('<html>\') output.write('<head>\ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\<head>\') output.write("%s" % (ad)) output.write('\</html>\') output.close()
欢迎点击
0 0
- Python发送http请求解析返回json小demo
- Java发送Http请求,解析html返回
- Java发送Http请求,解析html返回
- Java发送Http请求,解析html返回
- Java发送Http请求,解析html返回
- Java发送Http请求,解析html返回
- Java发送Http请求,解析html返回
- Android发送http请求并解析json
- http请求返回并解析json数据
- http请求返回并解析json数据
- Python发送http请求(json格式)
- python 发送HTTP请求 post json 格式
- http发送json格式数据请求 demo示例
- 基本HTTP请求+JSON解析+发送异步请求
- http+json发送请求
- python http请求post参数,json解析
- java发送http请求,解析html返回的技术
- swift http请求返回json数据并解析
- 【排序算法】之快速排序
- 蓝桥杯——趣味逻辑推理一(2017.2.16)
- 跟小博老师一起学Servlet ——Servlet之客户端跳转
- C# as is的用法
- 跨浏览器的事件监听
- Python发送http请求解析返回json小demo
- 中断的概念
- 极简-聊天-UI100
- 有符号数和无符号数负数
- Visual Studio 2015 professional 密钥
- Python传输解析PB消息Client段程序
- hduCoconuts(离散化)
- android 模拟触摸板控制鼠标(解决小屏幕控制大屏幕)
- Mybatis高级应用-嵌套查询association和collection