首页后端开发其他后端知识记录Python安装wordpress_xmlrpc库实现离线发布文章

记录Python安装wordpress_xmlrpc库实现离线发布文章

时间2023-04-19 20:18:01发布访客分类其他后端知识浏览247
导读:这几天老蒋有在研究Python爬虫推送文章给WordPress CMS,这里我们一般使用的是xmlrpc.php协议推送的,这里需要安装到wordpress_xmlrpc库实。这里简单的整理网上通用的库和脚本便于以后的学习。1、安装库pip...

这几天老蒋有在研究Python爬虫推送文章给WordPress CMS,这里我们一般使用的是xmlrpc.php协议推送的,这里需要安装到wordpress_xmlrpc库实。这里简单的整理网上通用的库和脚本便于以后的学习。

1、安装库

pip install python_wordpress_xmlrpc

这里需要安装库。

2、示范脚本

from wordpress_xmlrpc import Client, WordPressPostfrom wordpress_xmlrpc.methods import postswp = Client('https://domain.com/xmlrpc.php', 'username', 'password')def post_new_article(title, content):    post = WordPressPost()    post.title = title    post.content = content    post.post_status = 'draft'  # 文章状态,不写默认是草稿,private表示私密的,draft表示草稿,publish表示发布    post.terms_names = {
        'category': ['分类目录'],        'post_tag': ['标签1', '标签2'],    }
    post.id = wp.call(posts.NewPost(post))    return post.id

示范看看:

# -*- coding: utf-8 -*-from wordpress_xmlrpc import Client, WordPressPostfrom wordpress_xmlrpc.methods import postsusername="管理员用户名"password="管理员密码"apiurl="http://域名/xmlrpc.php" #网站xmlrpc路径wp = Client(apiurl,username, password,)print(wp)post = WordPressPost()post.title = '文章标题2'post.content = '文章内容'post.post_status = 'publish' #文章状态,不写默认是草稿,private表示私密的,draft表示草稿,publish表示发布post.terms_names = {
    'post_tag': ['test', 'firstpost'], #文章所属标签,没有则自动创建    'category': ['Introductions', 'Tests'] #文章所属分类,没有则自动创建 }
    post.id = wp.call(posts.NewPost(post))print(post.id)

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

Python发布wordpress_xmlrpc库WordPress爬虫

若转载请注明出处: 记录Python安装wordpress_xmlrpc库实现离线发布文章
本文地址: https://pptw.com/jishu/3899.html
PyCharm编辑器安装requests库方法 如何设置Typecho程序伪静态规则 设置固定链接

游客 回复需填写必要信息