偉大的python可以無所不能,目前小的工作都交給Python處理了旭愧,以下代碼演示通過蘋果接口獲取App數(shù)據(jù)的方法。
#!/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);