python xmlrpc_Python xmlrpc用法

Python xmlrpc是一款非常好用的工具,特别是在python+wordpress的架构下,可以快速地完成一个网站内容的填充。所以,除了熟悉它的一些基本用法,掌握它的高级用法也是非常重要的。

一、显示所有的目录

from wordpress_xmlrpc import Client, WordPressPost

from wordpress_xmlrpc.methods.posts import GetPosts

from wordpress_xmlrpc.methods import posts

from wordpress_xmlrpc import WordPressTerm

from wordpress_xmlrpc.methods import taxonomies

wp = Client('http://127.0.0.1/15wp/xmlrpc.php', 'admin', '123456')

categories = wp.call(taxonomies.GetTerms('category'))

for i in categories:

print(i)

二、显示job_listing的目录名称

categories = wp.call(taxonomies.GetTerms('job_listing_category'))

for i in categories:

print(i)

结果:

广东

广西

湖南

福建

三、显示某目录名称

显示id为8的目录名称。

category = wp.call(taxonomies.GetTerm('category', 8))

print(category)

结果:

#antiquarianism

三、显示某类型的文章

from wordpress_xmlrpc import Client, WordPressPost

from wordpress_xmlrpc.methods.posts import GetPosts

from wordpress_xmlrpc.methods import posts

from wordpress_xmlrpc import WordPressTerm

wp = Client('http://127.0.0.1/15wp/xmlrpc.php', 'admin', '123456')

posts = wp.call(posts.GetPosts({ 'post_type': 'job_listing'}))

for post in posts:

print(post)

三、返回博客支持的文章格式

posts = wp.call(posts.GetPostFormats())

print(posts)

其中一个是all,一个是supported.

四、返回博客支持的文章类型

posts = wp.call(posts.GetPostTypes())

for post in posts:

print(post)

可以看到,因为我安装了wp job manager 插件,所以有job_listing的文章类型。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值