当前位置: 移动技术网 > IT编程>脚本编程>Python > 自己编写一个wordpress导出的xml提取脚本

自己编写一个wordpress导出的xml提取脚本

2018年07月31日  | 移动技术网IT编程  | 我要评论

鬼面獒,查开房网址输姓名可查开房信息,凯文 杜兰特

百度了一下,好像没有相关的脚本.而且.各大博客网站都不能直接导入QAQ.于是本着自给自足的原则自己写了一个.

使用的语言为python

只提取文章的标题和内容

会在脚本运行的目录下生成一个文件夹,文件夹名是当前时间的时间戳.生成的txt在该文件夹下,以标题名命名.

文件名以wordpress.xml为例

import xml.etree.ElementTree as ET
import time
nowTime = str(int(time.time()))
import os

def mkdir(path):
    folder = os.path.exists(path)
    if not folder:  # 判断是否存在文件夹如果不存在则创建为文件夹
        os.makedirs(path)  # makedirs 创建文件时如果路径不存在会创建这个路径

mkdir(nowTime)
tree = ET.parse('wordpress.xml')
rss = tree.getroot()
channel = rss.find('channel')
for item in channel.iter('item'):
    title = item.find('title').text
    content = item.find('{http://purl.org/rss/1.0/modules/content/}encoded').text
    try:
        if(content != None):
            f = open(nowTime + '/' + title + '.txt', 'w')
            f.write(title+'\n')
            f.write(content)
            f.close()
    except:
        print(title)
        print(content)
print('end')

转载请注明来自:LucyTime 原文地址:

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网