そこでリストを作っておいて、何が増えたのか把握したい。
#!/usr/bin/python # -*- encoding: utf-8 -*- import re import codecs import urllib from datetime import datetime import simplejson as json def main(): f = urllib.urlopen('http://www.ted.com/talks/listRPC/lang/jpn') raw_talks = json.load(f) talks = list() for t in raw_talks['resultSet']['result']: mtitle = re.search(r'title="([^"]*)"', t['markup']) mhref = re.search(r'href="([^"]*)"', t['markup']) talks.append({'title': mtitle.group(1), 'href': mhref.group(1)}) talks.sort(lambda x, y: cmp(x['href'], y['href'])) f = codecs.open(datetime.now().strftime('%Y%m%d_%H%M%S'), 'w', 'utf-8') for t in talks: f.write(u'%s\n%s\n' % (t['title'], t['href'])) if __name__ == '__main__': main()
0 件のコメント:
コメントを投稿