Last active
October 2, 2020 08:22
-
-
Save sharkdeng/3092319f27376bb86ac38b6c833aabd6 to your computer and use it in GitHub Desktop.
turn wordpress xml to txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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