微慑信息网

python深入操控wordpress之半自动化(二)

前提:部分主题关闭了xmlrpc,将会报错;

先定义个全局变量:

def main():
    global wpUrl,wpUser,wpPass,wp
    wpUrl='http://word.press/xmlrpc.php'
    wpUser='admin'
    wpPass='admin'
    wp = Client(wpUrl, wpUser, wpPass)

 

1、获取分类:

(1)仅获取分类名称:

def getcateBase():
    categories = wp.call(taxonomies.GetTerms('category'))
    return categories

(2)获取分类ID及名称,根据自己需要即可

def getcate():
    categories = wp.call(taxonomies.GetTerms('category'))
    mCategory={}
    for i in categories:
        mCategory[i.id]=i.name
    mCategory =  (eval(json.dumps(mCategory)))
    #print (mCategory)
    return mCategory

2、根据ID获取文章对应ID 信息:

GetPost中的属性及方法:

[‘__class__’, ‘__delattr__’, ‘__dict__’, ‘__dir__’, ‘__doc__’, ‘__eq__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__gt__’, ‘__hash__’, ‘__init__’, ‘__le__’, ‘__lt__’, ‘__module__’, ‘__ne__’, ‘__new__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__repr__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__subclasshook__’, ‘__weakref__’, ‘_def’, ‘comment_status’, ‘content’, ‘custom_fields’, ‘date’, ‘date_modified’, ‘definition’, ‘excerpt’, ‘guid’, ‘id’, ‘link’, ‘menu_order’, ‘mime_type’, ‘parent_id’, ‘password’, ‘ping_status’, ‘post_format’, ‘post_status’, ‘post_type’, ‘slug’, ‘sticky’, ‘struct’, ‘terms’, ‘thumbnail’, ‘title’, ‘user’]

def getArtById(artId):
    res = wp.call(GetPost(artId))
    user =res.user
    title =str(res.title)
    slug = res.slug #别名
    struct = res.struct#详情
    return title,user,slug,struct
    

 

3、其他根据API开箱使用即可:

4、效果:

其他:

post.date = datetime.datetime.now()    发布时间

post.date_modified =   修改时间

 

https://blog.csdn.net/weixin_34233421/article/details/93719686

插入时支持的参数有:

 python中字段  xmlrpc对应字段 含义
date post_date_gmt
date_modified post_modified_gmt  post的修改时间
slug post_name
post_status post_status  post的状态, 可选draft、publish,常用publish就可以直接发布post了
title   post标题
content post_content  post 内容
excerpt post_excerpt  摘要
link
comment_status
ping_status
terms
terms_names
custom_fields
enclosure
post_format
thumbnail post_thumbnail
sticky  置顶显示, 设置True
post_type  post的类型, 默认为post, 也可以为page,
parent_id post_parent  上级文章的id
menu_order
guid
mime_type post_mime_type

https://blog.csdn.net/weixin_34233421/article/details/93719686

https://python-wordpress-xmlrpc.readthedocs.io/en/latest/ref/methods.html

http://blog.sina.com.cn/s/blog_12d84817c0102wsu5.html

https://blog.csdn.net/u011537073/article/details/87892617

XML-RPC Modernization

其他:

  File "C:\Python39\lib\site-packages\wordpress_xmlrpc\base.py", line 37, in call
    raw_result = server_method(*args)
  File "C:\Python39\lib\xmlrpc\client.py", line 1116, in __call__
    return self.__send(self.__name, args)
  File "C:\Python39\lib\xmlrpc\client.py", line 1458, in __request
    response = self.__transport.request(
  File "C:\Python39\lib\xmlrpc\client.py", line 1160, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:\Python39\lib\xmlrpc\client.py", line 1176, in single_request
    return self.parse_response(resp)
  File "C:\Python39\lib\xmlrpc\client.py", line 1342, in parse_response
    p.feed(data)
  File "C:\Python39\lib\xmlrpc\client.py", line 445, in feed
    self._parser.Parse(data, False)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1051, column 113316

查询语句中增加orderby:

'orderby':'post_modified','order': 'ASC'

 

赞(0) 打赏
转载请附本站链接,未经允许不得转载,,谢谢:微慑信息网-VulSee.com » python深入操控wordpress之半自动化(二)

评论 抢沙发

微慑信息网 专注工匠精神

微慑信息网-VulSee.com-关注前沿安全态势,聚合网络安全漏洞信息,分享安全文档案例

访问我们联系我们

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册