admin管理员组

文章数量:1602103

(function(){

if(''){

if (prompt('请输入文章密码') !== ''){

alert('密码错误!');

history.back();

}

}

})();

var NexT = window.NexT || {};

var CONFIG = {

hostname: new URL('https://kechenhh.gitee.io').hostname,

root: '/',

scheme: 'Gemini',

version: '7.7.0',

exturl: false,

sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},

copycode: {"enable":false,"show_result":false,"style":null},

back2top: {"enable":true,"sidebar":false,"scrollpercent":false},

bookmark: {"enable":false,"color":"#222","save":"auto"},

fancybox: false,

mediumzoom: false,

lazyload: false,

pangu: false,

comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},

algolia: {

appID: '',

apiKey: '',

indexName: '',

hits: {"per_page":10},

labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}

},

localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},

path: 'search.xml',

motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}

};

// https://hexo.io/docs/variables.html

CONFIG.page = {

sidebar: "",

isHome: false,

isPost: true

};

python使用xmlrpc自动发布文章到wordpress | 我的博客

.use-motion .brand,

.use-motion .menu-item,

.sidebar-inner,

.use-motion .post-block,

.use-motion .pagination,

.use-motion ments,

.use-motion .post-header,

.use-motion .post-body,

.use-motion .collection-header { opacity: initial; }

.use-motion .site-title,

.use-motion .site-subtitle {

opacity: initial;

top: initial;

}

.use-motion .logo-line-before i { left: initial; }

.use-motion .logo-line-after i { right: initial; }

我的博客

my blog

  • 首页

  • 标签

  • 分类

  • 归档

  • 搜索

placeholder="搜索..." spellcheck="false"

type="text" id="search-input">

0%

python使用xmlrpc自动发布文章到wordpress

发表于

2020-01-17

更新于

2020-12-19

分类于

Python

模块的使用方法看 https://python-wordpress-xmlrpc.readthedocs.io/en/latest/

安装:

带有自定义栏目字段的发布文章代码

1234567891011121314151617181920212223242526272829303132333435
#coding:utf-8from wordpress_xmlrpc import Client, WordPressPostfrom wordpress_xmlrpc.methods.posts import GetPosts, NewPostfrom wordpress_xmlrpc.methods.users import GetUserInfofrom wordpress_xmlrpc.methods import postsfrom wordpress_xmlrpc.methods import taxonomiesfrom wordpress_xmlrpc import WordPressTermfrom wordpress_xmlrpcpat import xmlrpc_clientfrom wordpress_xmlrpc.methods import media, postsimport sysreload(sys)sys.setdefaultencoding('utf-8')wp = Client('http://您的域名/xmlrpc.php', '后台账号', '后台密码')post = WordPressPost()post.title = '文章标题'post.content = '文章内容'post.post_status = 'publish' #文章状态,不写默认是草稿,private表示私密的,draft表示草稿,publish表示发布post.terms_names = {    'post_tag': ['test', 'firstpost'], #文章所属标签,没有则自动创建    'category': ['Introductions', 'Tests'] #文章所属分类,没有则自动创建 }post.custom_fields = []   #自定义字段列表post.custom_fields.append({  #添加一个自定义字段        'key': 'price',        'value': 3})post.custom_fields.append({ #添加第二个自定义字段        'key': 'ok',        'value': '天涯海角'})post.id = wp.call(posts.NewPost(post))</pre>

带有特色图像缩略图的发布文章

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
#coding:utf-8from wordpress_xmlrpc import Client, WordPressPostfrom wordpress_xmlrpc.methods.posts import GetPosts, NewPostfrom wordpress_xmlrpc.methods.users import GetUserInfofrom wordpress_xmlrpc.methods import postsfrom wordpress_xmlrpc.methods import taxonomiesfrom wordpress_xmlrpc import WordPressTermfrom wordpress_xmlrpcpat import xmlrpc_clientfrom wordpress_xmlrpc.methods import media, postsimport sysreload(sys)sys.setdefaultencoding('utf-8')wp = Client('http://您的域名/xmlrpc.php', '后台账号', '后台密码')filename = './my.jpg' #上传的图片文件路径# prepare metadatadata = {        'name': 'picture.jpg',        'type': 'image/jpeg',  # mimetype}# read the binary file and let the XMLRPC library encode it into base64with open(filename, 'rb') as img:        data['bits'] = xmlrpc_client.Binary(img.read())response = wp.call(media.UploadFile(data))# response == {#       'id': 6,#       'file': 'picture.jpg'#       'url': 'http://www.example/wp-content/uploads/2012/04/16/picture.jpg',#       'type': 'image/jpeg',# }attachment_id = response['id']post = WordPressPost()post.title = '文章标题'post.content = '文章正文'post.post_status = 'publish'  #文章状态,不写默认是草稿,private表示私密的,draft表示草稿,publish表示发布post.terms_names = {    'post_tag': ['test', 'firstpost'], #文章所属标签,没有则自动创建    'category': ['Introductions', 'Tests'] #文章所属分类,没有则自动创建 }post.thumbnail = attachment_id #缩略图的idpost.id = wp.call(posts.NewPost(post))

单独创建新的分类和标签

12345678910111213141516171819202122232425262728293031323334
#coding:utf-8from wordpress_xmlrpc import Client, WordPressPostfrom wordpress_xmlrpc import WordPressTermfrom wordpress_xmlrpc.methods import taxonomiesimport sysreload(sys)sys.setdefaultencoding('utf-8')wp = Client('http://您的域名/xmlrpc.php', '后台账号', '后台密码')#新建标签tag = WordPressTerm()tag.taxonomy = 'post_tag'tag.name = 'My New Tag12'#标签名称tag.slug = 'bieming12'#标签别名,可以忽略tag.id = wp.call(taxonomies.NewTerm(tag))#返回的id#新建分类cat = WordPressTerm()cat.taxonomy = 'category'cat.name = 'cat1'#分类名称cat.slug = 'bieming2'#分类别名,可以忽略cat.id = wp.call(taxonomies.NewTerm(cat))#新建分类返回的id#新建子分类parent_cat = client.call(taxonomies.GetTerm('category', 20))#20是父分类的idchild_cat = WordPressTerm()child_cat.taxonomy = 'category'child_cat.parent = parent_cat.idchild_cat.name = 'My Child Category'#分类名称child_cat.slug = 'beidongdui'#分类别名,可以忽略child_cat.id = wp.call(taxonomies.NewTerm(child_cat))#新建分类返回的id

# Python

Python打包成exe

AnyProxy抓包工具

window.addEventListener('tabs:register', () => {

let activeClass = CONFIGments.activeClass;

if (CONFIGments.storage) {

activeClass = localStorage.getItem('comments_active') || activeClass;

}

if (activeClass) {

let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);

if (activeTab) {

activeTab.click();

}

}

});

if (CONFIGments.storage) {

window.addEventListener('tabs:click', event => {

if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;

let commentClass = event.target.classList[1];

localStorage.setItem('comments_active', commentClass);

});

}

  • 文章目录

  • 站点概览

  1. 1. 安装:
  2. 2. 带有自定义栏目字段的发布文章代码
  3. 3. 带有特色图像缩略图的发布文章
  4. 4. 单独创建新的分类和标签

src="/images/avatar.gif">

kechenhh

学习笔记

20

日志

9

分类

12

标签

GitHub

©

2021

kechenhh

由 Hexo 强力驱动 v4.2.1

|

主题 – NexT.Gemini v7.7.0

一键复制

编辑

Web IDE

原始数据

按行查看

历史

本文标签: 批量文章wordpressPythonxmlrpc