先日[Python3.x]lxml 3.1.0を用いて巨大なxmlファイルの処理をゴリ押すでWikipediaの概要を取得するためにxmlで頑張ったのだが、記事で最後に述べたようにParser使わずに普通にテキスト処理したほうが速くね?ということに気がついてしまったので一応書いておく。
前回のはただのPythonの勉強だよ!
1 2 3 4 5 6 7 8 |
if __name__ == '__main__': with open('jawiki-20130216-abstract.xml', encoding='utf-8') as ifile: with open('abstract.txt',mode='w',encoding='utf-8') as ofile: for line in ifile: if line.find('<abstract>') != -1: line = line.replace('<abstract>','') ofile.write(line.replace('</abstract>','')) print("finish!") |
やっぱ酒飲むと(ry