最近試了 blogtrans (稍微修改版) 將 PIXNET 網誌備份格式從 MT 轉成 XML 格式,順便研究一下,所以就需要有一支 parser 來處理。
找了一下,在 python 套件中有一套 feedparser 可以使用,十分方便:
$ sudo port install py27-feedparser
用法:
$ ipython
Python 2.7.5 (default, May 28 2013, 22:38:37)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import feedparser
In [2]: xml = feedparser.parse('/tmp/test.xml')
In [3]: xml.entries[0].keys()
Out[3]:
['updated',
'updated_parsed',
'published_parsed',
'tags',
'title',
'links',
'summary',
'content',
'guidislink',
'title_detail',
'href',
'link',
'author',
'published',
'authors',
'author_detail',
'id']
In [4]: for e in xml.entries:
...: print e.title
...:
沒有留言:
張貼留言