当前位置:首页 > Python笔记 > 正文内容

python利用 xmlrpc操作WordPress自动发布文章

# encoding:utf-8
import pymysql
import requests
import json
import base64
import requests
import base64
from datetime import datetime
import time
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods import posts
# 连接数据库
conn_weixin = pymysql.connect(
   host='42.236.82.14',
   user='weiji',
   password='sWEms5TKewFtnfiC',
   database='wcaiji',
   charset='utf8mb4', )
cursor_weixin = conn_weixin.cursor(cursor=pymysql.cursors.DictCursor)
#取一条数据
sql= f''' select * from xiaohongshu_url where status=1  order by id asc  limit 1 '''
cursor_weixin.execute(sql)
res = cursor_weixin.fetchone()
print(res['title'])
if res['wangzhan_id']==103:
   wp = Client('https://www.seda.com/xmlrpc.php', 'w32ang', 'xiao23qiang1233')
   post = WordPressPost()
   post.title = res['title']
   post.content = res['title']+res['imgs']+res['content_yuanma']
   post.post_status = 'publish'  # 文章状态,不写默认是草稿,private表示私密的,draft表示草稿,publish表示发布
   post.terms_names = {
       'category': ['手机应用'],
       'category': ['软件仓库'],
   }
   post.id = wp.call(posts.NewPost(post))
   print(post.id)

微信截图_20240507105744.png

发表评论

(必填)
(必填)
(选填)

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新留言

标签列表