Skip to content

Instantly share code, notes, and snippets.

@sharkdeng
Last active October 2, 2020 08:22
Show Gist options
  • Select an option

  • Save sharkdeng/3092319f27376bb86ac38b6c833aabd6 to your computer and use it in GitHub Desktop.

Select an option

Save sharkdeng/3092319f27376bb86ac38b6c833aabd6 to your computer and use it in GitHub Desktop.
turn wordpress xml to txt
## this snippet allows you to fastly convert post from wordpress xml format to txt
from xml.dom.minidom import parse, parseString
import os
dom = parse('jobyme88.xml') # parse an XML file by name
os.path.makedirs('blogs')
items = dom.getElementsByTagName('item')
for item in items:
title = item.getElementsByTagName('title')
title = title[0].firstChild.nodeValue
content = item.getElementsByTagName('content:encoded')
content = content[0].firstChild.nodeValue
print(content)
f = open(f'blogs/{title}.txt', 'w')
f.write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment