伟大的python可以无所不能,目前小的工作都交给Python处理了,以下代码演示通过苹果接口获取App数据的方法。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import urllib2
import demjson
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def writeLine(file,content):
file.write(content)
def getAppInfo(appid):
url = "http://itunes.apple.com/lookup?id=%d&country=cn" % (appid)
req = urllib2.Request(url);
resdata = urllib2.urlopen(req)
res = resdata.read()
json = demjson.decode(res)
file = "%d.txt" % (appid)
f = open(file, "w+")
writeLine(f, ('=====appid=====:\n' + (str)(json['results'][0]['trackId'])) + '\n')
writeLine(f, ('=====trackName=====:\n' + json['results'][0]['trackName']) + '\n')
writeLine(f, ('=====description=====:\n' + json['results'][0]['description'] + '\n'))
writeLine(f, ('=====link=====:\n' + json['results'][0]['trackViewUrl'] + '\n'))
writeLine(f, ('=====bundleId=====:\n' + (str)(json['results'][0]['bundleId']) + '\n'))
writeLine(f, ('=====releaseAt=====:\n' + json['results'][0]['currentVersionReleaseDate'] + '\n'))
writeLine(f, ('=====releaseNotes=====:\n' + json['results'][0]['releaseNotes'] + '\n'))
writeLine(f, ('=====icon=====:\n' + json['results'][0]['artworkUrl100'] + '\n'))
writeLine(f, ('=====fileSizeBytes=====:\n' + (str)(json['results'][0]['fileSizeBytes']) + '\n'))
f.close()
getAppInfo(1102002763);
网友评论