国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python發送http請求解析返回json的實例

2020-02-22 23:34:00
字體:
來源:轉載
供稿:網友

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()

以上這篇Python發送http請求解析返回json的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鄂伦春自治旗| 开鲁县| 加查县| 盐山县| 林甸县| 茂名市| 卢湾区| 永济市| 揭西县| 县级市| 娄底市| 玛沁县| 金川县| 寿光市| 贵定县| 九江市| 综艺| 昆山市| 南丹县| 霍山县| 定兴县| 沭阳县| 芦溪县| 温宿县| 武鸣县| 大石桥市| 旺苍县| 吉木乃县| 泰兴市| 平果县| 周宁县| 惠州市| 东莞市| 谷城县| 阜南县| 布尔津县| 郁南县| 加查县| 岱山县| 洞口县| 白城市|