要使用 WordPress XML-RPC API,您需要安装 python-wordpress-xmlrpc
模块。以下是安装步骤:
python-wordpress-xmlrpc
模块:pip install python-wordpress-xmlrpc
Select CodeCopy
pip3 install python-wordpress-xmlrpc
Select CodeCopy
安装完成后,您可以使用以下代码示例连接到WordPress 网站直接发布文章:
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost
wp_url = ‘https://yourwebsite.com/xmlrpc.php’
wp_username = ‘your_username’
wp_password = ‘your_password’
wp = Client(wp_url, wp_username, wp_password)
post = WordPressPost()
post.title = ‘My New Title’
post.content = ‘This is the body of my new post.’
post.terms_names = {
‘post_tag’: [‘tag1’, ‘tag2’],
‘category’: [‘My Category’]
}
wp.call(NewPost(post))
Select CodeCopy
请替换 wp_url
,wp_username
和 wp_password
为您 WordPress 站点的实际信息,即可连接到您的 WordPress 网站。
powered by kaifamiao