使用Python脚本批量添加WordPress文章

1.9k Python 发表评论

我们用到Wordpress的xmlrpclib,步骤:

  1. 安装python 和 xmlpc
  2. 然后用下面代码新增一篇文章:
 import datetime, xmlrpclib

wp_url = "http://garymeng.com/xmlrpc.php"
wp_username = ""
wp_password = ""
wp_blogid = ""
publish = True

server = xmlrpclib.ServerProxy(wp_url)

title = "This is title"
content = "This is content"
date_created = xmlrpclib.DateTime(datetime.datetime.strptime("2011-10-20 21:08", "%Y-%m-%d %H:%M"))
categories = ["category here"]
tags = ["sometag", "othertag"] 
data = {'title': title, 'description': content, 'dateCreated': date_created, 'categories': categories, 'mt_keywords': tags}

post_id = server.metaWeblog.newPost(wp_blogid, wp_username, wp_password, data, publish)

print(post_id)

文章来源:http://panks.me/posts/2012/06/add-post-to-your-wordpress-blog-using-python-script/

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

昵称 *