从json python中提取键值

时间:2015-09-22 12:56:39

标签: json angularjs python-2.7 parsing

我想要帮助提取" url"价值来自 - https://www.udemy.com/api-2.0/channels/1640/courses?is_angular_app=true&p=2

import urllib2, json
response = urllib2.urlopen('https://www.udemy.com/api-2.0/channels/1640/courses?is_angular_app=true&p=2')
data = json.load(response)

for data["url"] in data.items():
    print data["url"]

它不起作用。请帮忙

2 个答案:

答案 0 :(得分:0)

使用此代码,您可以获得第一个数组的URL

/^(\/path.+|(?!\/path).*)$/

使用for循环获取每个数组的所有网址

import urllib2, json
response = urllib2.urlopen('https://www.udemy.com/api-2.0/channels/1640/courses?is_angular_app=true&p=2')
data = json.load(response)

print data['results'][0]['url']

答案 1 :(得分:0)

试试这个:

import urllib2, json
response = urllib2.urlopen('https://www.udemy.com/api-2.0/channels/1640/courses?is_angular_app=true&p=2')
data = json.load(response)
for i in range(len(data['results'])):
   print data['results'][i]['url']