-1
目前,我有它解析JSON API下列..獲取從JSON鍵對應的值在Python
import simplejson
import urllib2
f = urllib2.urlopen('http://fanart.tv/webservice/series/f5b8e776c35e7536eac132802b03281f/80349/json/tvthumb/')
data = simplejson.load(f)
imagetypes = ['clearlogo', 'clearart', 'tvthumb', 'seasonthumb', 'characterart']
image_list = []
# split "name" and "data"
for title, value in data.iteritems():
# run through specified types
for art in imagetypes:
# if type has been found
if value.has_key(art):
# Run through all the items
for item in value[art]:
info = {}
info['url'] = urllib2.quote(item['url'], ':/') # Original image url
if info:
image_list.append(info)
print image_list
這將返回以下..
[{'url': 'http://fanart.tv/fanart/tv/80349/tvthumb/5287/C_80349%20%284%29.jpg'},
{'url': 'http://fanart.tv/fanart/tv/80349/tvthumb/5286/C_80349%20%285%29.jpg'},
{'url': 'http://fanart.tv/fanart/tv/80349/tvthumb/5288/C_80349%20%283%29.jpg'},
{'url': 'http://fanart.tv/fanart/tv/80349/tvthumb/5289/C_80349%20%282%29.jpg'},
{'url': u'http://fanart.tv/fanart/tv/80349/tvthumb/5290/C_80349.jpg'}, {'url':
'http://fanart.tv/fanart/tv/80349/tvthumb/5291/C_80349%20%280%29.jpg'}]
我如何去獲得公正將實際的網址轉換爲網址列表?如果你能解釋你的答案中的步驟,所以我可以從中學習,我會很感激。謝謝
我不知道我明白你在問什麼。你創建一個字典並將URL放在它的''url''鍵下。現在,你問怎麼不把這個URL包裝在一個字典中?那麼你爲什麼首先這樣做? – 2012-03-28 19:50:06