安装python wordpress xmlrpc
pip install python_wordpress_xmlrpc
获取文章对象
根据指定的post id获取文章对象WordPressPost
def get_post(self, post_id):
'''
通过指定的post id查询文章(页面)对象
:return:
'''
page = self.wp.call(posts.GetPost(post_id))
print(f'id={page.id},title={page.title}')
return page
编辑文章
调用编辑方法editPost()
def edit_post(self, post_id):
file_name = self.file_path.split('/')[-1]
file_content = self.__read_md_file(self.file_path)
post = self.get_post(post_id)
# post = WordPressPost()
post.title = file_name.split('.')[0]
post.content = f'''
{file_content}
'''
post.id = self.wp.call(posts.EditPost(post.id, post))
print(f'\nid={post.id}')
print(f'发布修改文章:{file_name}')
return post.id
当前文章价值7.73元,扫一扫支付后添加微信提供帮助!(如不能解决您的问题,可以申请退款)

评论已关闭!