使用python在wordpress博客网站添加新文章示例

Wodrepress是最近很火的一个博客平台,利用它可以快速搭建各种网站。下面我是利用xmlrpc编程接口在wordpress添加文章的示例代码:

import datetime, xmlrpclib
wp_url = "http://www.example.com/xmlrpc.php"
wp_username = "someuser"
wp_password = "secret"
wp_blogid = ""

status_draft = 0
status_published = 1

server = xmlrpclib.ServerProxy(wp_url)

title = "Title with spaces"
content = "Body with lots of content"
date_created = xmlrpclib.DateTime(datetime.datetime.strptime("2009-10-20 21:08", "%Y-%m-%d %H:%M"))
categories = ["somecategory"]
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, status_published)


原文地址:https://www.cnblogs.com/AlexanderZhao/p/12879010.html