# 安装wordpress的python库
pip install python-wordpress-xmlrpc
# 导入库
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
# 登录wordpress
wp = Client('http://www.example.com/xmlrpc.php', 'username', 'password')
# 获取用户信息
user_info = wp.call(GetUserInfo())
# 获取本地图片列表
import os
from os import listdir
from os.path import isfile, join
mypath = 'C:/Users/Desktop/images/'
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
# 循环发布图片
for file in onlyfiles:
post = WordPressPost()
post.title = file
post.content = '<img src="http://www.example.com/images/' + file + '">'
post.post_status = 'publish'
post.terms_names = {
'post_tag': ['python', 'wordpress'],
'category': ['python']
}
wp.call(NewPost(post))
```
python本地图片批量发布到wordpress
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《python本地图片批量发布到wordpress》
文章链接:https://www.gebizhan.com/1703.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
文章名称:《python本地图片批量发布到wordpress》
文章链接:https://www.gebizhan.com/1703.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。