Skip to content

Instantly share code, notes, and snippets.

@gh640
Created February 11, 2013 13:47
Show Gist options
  • Save gh640/4754500 to your computer and use it in GitHub Desktop.
Save gh640/4754500 to your computer and use it in GitHub Desktop.
Google Reader登録フィードのURL一覧を表示。
# coding: utf-8
# XMLをParseするためのクラスparseをインポート
from xml.etree.ElementTree import parse
# Google readerの登録フィードを読み込み、
# body要素の子にあるすべてのoutline要素のリストを取得してelesに
tree = parse("google-reader-subscriptions.xml")
eles = tree.getroot().find("body").findall("outline")
# ループを回して全URLを表示
# totalnum: 登録フィードの総数をカウント
# list(e): 要素eの子ノードをiterate
# e.get('htmlUrl'): 要素eの属性htmlUrlの値を取得
# if len(list(e)) > 0: eはフィードorタグ eがカテゴリを表す場合にTrueとなる
totalnum = 0
for e in eles:
if len(list(e)) > 0:
for echild in list(e):
print echild.get('htmlUrl')
totalnum += 1
else:
print e.get('htmlUrl')
totalnum += 1
print 'total subscriptions:', totalnum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment