python csv wordpress xmlrpc_python使用xmlrpc对wordpress增加文章

这两天搞的,python使用xmlrpc对wordpress增加文章,为了配合使用python用邮件向wordpress增加文章的实验,现在都做得差不多了,记录下代码!

#coding=gbk

import xmlrpclib

def send_data_to_wp(wp_url,wp_username,wp_password,title,content,tags,fenlei):

wp_blogid=”

status_published = 0

server = xmlrpclib.ServerProxy(wp_url)

aa=fenlei

#中文的gbk转换成utf8格式, 不转换是会出错

aa=aa.decode(‘gbk’,’ignore’).encode(‘utf8′,’ignore’)

categories = [aa]

#中文的gbk转换成utf8格式

title=title.decode(‘gbk’,’ignore’).encode(‘utf8′,’ignore’)

#中文的gbk转换成utf8格式

content=content.decode(‘gbk’,’ignore’).encode(‘utf8′,’ignore’)

data = {‘title’: title, ‘description’: content, ‘categories’: categories, ‘mt_keywords’: tags,’post_status’:’publish’}

print data

post_id = server.metaWeblog.newPost(wp_blogid, wp_username, wp_password, data, status_published)

return post_id

# 需要操作的wordpress

w_url = “http://192.168.5.25/wordpress/xmlrpc.php”

#登录用户

w_username = “admin”

#登录密码

w_password = “123456789”

#文章标签

w_tags = [“sometag”, “othertag”]

#文章题目

w_title=’中文测试’

#文章内容

w_content=’今天天气不错啊’

#文章分类

w_fenlei=’一般想到的’

print send_data_to_wp(w_url,w_username,w_password,w_title,w_content,w_tags,w_fenlei)

另外关于wordpress 的xmlrpc使用方法网址:http://codex.wordpress.org/XML-RPC_wp , 比较有用!

以下这段代码是列出xmlrpc的使用方法有哪些

mport xmlrpclib

from pprint import pprint

server = xmlrpclib.ServerProxy(“http://localhost/wordpress/xmlrpc.php”)

pprint(server.system.listMethods() )

这样应该比较方便应用了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值