做局域网网站教程,哪个搜索引擎最好,驻马店做网站优化,浙江建设信息港网站查询在我的上一篇文章中已经给出了python操作wordpress的环境和发布文字的教程#xff1a;
python直接发布到网站wordpress之一只发布文字-CSDN博客
本篇实现发布带图片的内容#xff0c;无图无真相嘛。
直接上代码#xff1a;
from wordpress_xmlrpc.methods.media import …在我的上一篇文章中已经给出了python操作wordpress的环境和发布文字的教程
python直接发布到网站wordpress之一只发布文字-CSDN博客
本篇实现发布带图片的内容无图无真相嘛。
直接上代码
from wordpress_xmlrpc.methods.media import UploadFile
from wordpress_xmlrpc import Client
from wordpress_xmlrpc import WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost# Your credentials
url http://你的域名.后缀名/xmlrpc.php
username 你的wordpress的账号名
password 你的wordpress的账号密码client Client(url, username, password)# Define your image and its properties
data {name: big_image.jpg,type: image/jpeg, # mimetype
}# Read the binary file and let the XMLRPC library encode it into base64
with open(big_image.jpg, rb) as img:data[bits] img.read()response client.call(UploadFile(data))
attachment_id response[id]def send_post(title, content, attachment_id):post WordPressPost()post.title titlepost.content contentpost.post_status publishpost.thumbnail attachment_idpost_id client.call(NewPost(post))# Call the function
send_post(Your Title, Your Content, attachment_id)
注big_image.jpg是和代码.py同目录下的要发布的图片文件。