菜鸟笔记
提升您的技术认知

python在wordpress上发布文章

首先安装 python-wordpress-xmlrpc

pip3 install python-wordpress-xmlrpc

# -*- coding: utf-8 -*-
import json
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost

id = 'user'
password = 'pwd'

url = 'http://wordpress.url/xmlrpc.php'

wp = Client(url, id, password)

post = WordPressPost()
post.post_status = 'publish'
post.title = '新的文章'
post.content = '这里是文章内容,不错噢'
post.excerpt = '这里是摘抄样式示例'
post.terms_names = {
"post_tag": ['Python'],
"category": ['Python']
}

wp.call(NewPost(post))