Skip to content

Instantly share code, notes, and snippets.

@yoshikinoue
Last active October 5, 2018 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshikinoue/2d208173cea6712d933e to your computer and use it in GitHub Desktop.
Save yoshikinoue/2d208173cea6712d933e to your computer and use it in GitHub Desktop.
feedlyのxmlをPythonで加工する。 ref: https://qiita.com/karumado/items/ec1cab6bb9e23e210116
[hoge](http://hoge/)
[fuga](http://fuga/)
[hoge](http://hoge/)
[fuga](http://fuga/)
#coding:utf-8
import xml.etree.ElementTree as ET
#xmlファイルの読み込み
tree = ET.parse('feedly.opml.xml')
root = tree.getroot()
#出力したいカテゴリ
category = 'Engineers Blog'
#findallに投げる検索対象
find_el = ".//outline[@text='%s']/outline[@type='rss']" % category
es = root.findall(find_el)
for e in es:
#辞書型のデータが得られる。
blog_data = e.attrib
title = ""
url = ""
#データを取り出す。
for key, value in blog_data.items():
if key == 'title':
title = value
elif key == 'xmlUrl':
url = value
print "[%s](%s)" % (title, url)
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>xxxx subscriptions in feedly Cloud</title>
</head>
<body>
<outline text="game" title="game">
<outline type="rss" text="更新情報|プレイステーション オフィシャルサイト" title="更新情報|プレイステーション オフィシャルサイト" xmlUrl="http://www.jp.playstation.com/whatsnew/whatsnew.rdf" htmlUrl="http://www.jp.playstation.com/index.html"/>
</outline>
</body>
</opml>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment