Python.Extracting Data from JSON
2016-07-24 20:05
489 查看
The program will prompt for a URL, read the JSON data from that URL using urllib and
then parse and extract the comment counts from the JSON data, compute the sum of the numbers in the file and enter the sum below
JSON地址:http://python-data.dr-chuck.net/comments_290549.json (Sum
ends with 90)
Python源码:
import urllib
import json
inp = raw_input('Enter location:')
url = urllib.urlopen(inp).read()
data = json.loads(url)
info = data['comments']
leng = len(info)
sum = 0
for i in range(leng):
num = info[i-1]['count']
sum = sum + num
print sum
运行结果:
Enter location:http://python-data.dr-chuck.net/comments_290549.json
2790
then parse and extract the comment counts from the JSON data, compute the sum of the numbers in the file and enter the sum below
JSON地址:http://python-data.dr-chuck.net/comments_290549.json (Sum
ends with 90)
Python源码:
import urllib
import json
inp = raw_input('Enter location:')
url = urllib.urlopen(inp).read()
data = json.loads(url)
info = data['comments']
leng = len(info)
sum = 0
for i in range(leng):
num = info[i-1]['count']
sum = sum + num
print sum
运行结果:
Enter location:http://python-data.dr-chuck.net/comments_290549.json
2790
相关文章推荐
- python读取excel文件
- Python函数第四节
- python核心编程第八章练习
- python核心编程第七章练习
- Python学习笔记20:Python Web编程
- python核心编程作业--正则表达式和图形界面--电影搜索器(电影天堂)
- Python开发柜员机系统
- Python学习笔记19:Python图形用户界面编程
- Python学习笔记18:Python多线程编程
- python图像主色调(主颜色)提取,在hsv空间k均值迭代实现
- python 编译过程 从py文件到bytecode
- 利用Python实现简单的相似图片搜索
- 迅雷离线网页版API
- python学习笔记--基础概要
- 【python】Python标准库defaultdict模块
- 【初学者教程】在电脑上安装Python,写第一个程序
- Python 之 pickle/json序列化 之 2
- python_Django之模板模型
- ubuntu 安装 python3 升级
- 【python】any()和all()