当前位置: 首页 > news >正文

江西个人网站备案做论坛客户关系管理

江西个人网站备案做论坛,客户关系管理,网站开发分为哪几块,如何自己做资源网站在前面的文章中,实现了使用python操作wordpress发布文字内容和图片内容。 python直接发布到网站wordpress之一只发布文字-CSDN博客 python直接发布到网站wordpress之二发布图片-CSDN博客 不过,此时发布图片的数量只能是一张图片。但在实际应用中&…

在前面的文章中,实现了使用python操作wordpress发布文字内容和图片内容。

python直接发布到网站wordpress之一只发布文字-CSDN博客

python直接发布到网站wordpress之二发布图片-CSDN博客 

不过,此时发布图片的数量只能是一张图片。但在实际应用中,在同一篇wordpress文章中,肯定会有多张图片的情况,本篇就是实现用python操作wordpress批量发布图片到一篇文章中(而不是批量发布多篇文章,每篇文章中各一张图片)。

怎么办呢?经过大量搜索,尤其是查阅python-wordpress-xmlrpc文档,链接如下:

Overview — python-wordpress-xmlrpc 2.3 documentation 

得知关键信息如下,即Upload上传附件(如图片)后,会返回其url:

 

利用这一点,编写批量上传并发布图片代码如下:

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost
from wordpress_xmlrpc.methods.media import UploadFile
# from wordpress_xmlrpc.compat import xmlrpc_client
import osimage_content_list=['图片1','图片2','图片3','图片4']
def create_gallery_post(images_folder, wordpress_url, wordpress_username, wordpress_password):# 登录到 WordPressclient = Client(wordpress_url, wordpress_username, wordpress_password)# 创建 WordPress 文章post = WordPressPost()post.title = "批量发布图片"post.content = "终于解决批量上传图片的问题了"post.excerpt = '解决!'# 遍历图片文件夹kk=0for filename in os.listdir(images_folder):if filename.endswith(".jpg") or filename.endswith(".jpeg") or filename.endswith(".png"):image_path = os.path.join(images_folder, filename)# 上传图片到 WordPressdata = {'name': filename,'type': 'image/jpeg',  # 或者其他图片格式}with open(image_path, 'rb') as img:data['bits'] = img.read()response = client.call(UploadFile(data))# response = client.call(client.get_method('wp.uploadFile'), data, img)attachment_id = response['id']img_url = response['url']print(attachment_id)print(img_url)print(type(attachment_id))#<class 'str'># 添加图片内容和图片url到文章内容中post.content +=image_content_list[kk]+'\n'+f'<img src="{img_url}" alt="{filename}" />'kk=kk+1# 发布图库文章到 WordPresspost.post_status = 'publish'client.call(NewPost(post))print("图库文章发布成功!")# 图片文件夹路径
images_folder = './jpg'  # 替换为实际的图片文件夹路径# WordPress 站点信息
wordpress_url = 'http://你的域名.后缀名/xmlrpc.php'
wordpress_username = '你的wordpress的账号名'
wordpress_password = '你的wordpress的账号密码'# 创建图库文章(含多张图片的文章)并发布到 WordPress
create_gallery_post(images_folder, wordpress_url, wordpress_username, wordpress_password)

注:images_folder = './jpg'是与pthon代码.py同目录下的、用于存放本次批量上传发布的图片的文件夹,程序会自动遍历其中的图片类型的文件并操作。 

 


文章转载自:
http://redetermination.stph.cn
http://poussin.stph.cn
http://iconography.stph.cn
http://decelerometer.stph.cn
http://spirituality.stph.cn
http://pomorze.stph.cn
http://fowler.stph.cn
http://papilionaceous.stph.cn
http://bargain.stph.cn
http://pali.stph.cn
http://lakefront.stph.cn
http://coltish.stph.cn
http://representative.stph.cn
http://nooky.stph.cn
http://smile.stph.cn
http://umohoite.stph.cn
http://retrobronchial.stph.cn
http://charter.stph.cn
http://juniper.stph.cn
http://hegari.stph.cn
http://aicpa.stph.cn
http://cabalist.stph.cn
http://moonlighting.stph.cn
http://babism.stph.cn
http://microlitre.stph.cn
http://filmmaking.stph.cn
http://chlorotrianisene.stph.cn
http://kebbok.stph.cn
http://mitchell.stph.cn
http://cadastre.stph.cn
http://sitosterol.stph.cn
http://vessel.stph.cn
http://hapchance.stph.cn
http://hemispheroidal.stph.cn
http://intussuscept.stph.cn
http://reprographic.stph.cn
http://eyedrop.stph.cn
http://quellenforschung.stph.cn
http://capitally.stph.cn
http://polyphagous.stph.cn
http://locule.stph.cn
http://carlish.stph.cn
http://hangar.stph.cn
http://dotal.stph.cn
http://refrangible.stph.cn
http://pyogenic.stph.cn
http://configure.stph.cn
http://amniote.stph.cn
http://choucroute.stph.cn
http://drag.stph.cn
http://cypriote.stph.cn
http://hagen.stph.cn
http://teapot.stph.cn
http://hypercorrect.stph.cn
http://overbred.stph.cn
http://fuddled.stph.cn
http://reword.stph.cn
http://fatted.stph.cn
http://heil.stph.cn
http://ramstam.stph.cn
http://acheulian.stph.cn
http://hamfooted.stph.cn
http://pedobaptism.stph.cn
http://neglectful.stph.cn
http://ropewalker.stph.cn
http://decalogue.stph.cn
http://doeth.stph.cn
http://trisyllable.stph.cn
http://girlcott.stph.cn
http://fashioner.stph.cn
http://rotovator.stph.cn
http://sapodilla.stph.cn
http://fascine.stph.cn
http://eosphorite.stph.cn
http://dialectology.stph.cn
http://besiege.stph.cn
http://emblazonment.stph.cn
http://erotic.stph.cn
http://microspore.stph.cn
http://mbira.stph.cn
http://viscountcy.stph.cn
http://nonenzyme.stph.cn
http://telling.stph.cn
http://scudo.stph.cn
http://basicity.stph.cn
http://pragmatist.stph.cn
http://individually.stph.cn
http://inconceivable.stph.cn
http://decillionth.stph.cn
http://joke.stph.cn
http://hirudinoid.stph.cn
http://lingua.stph.cn
http://catchy.stph.cn
http://stertorous.stph.cn
http://bathysphere.stph.cn
http://affirmance.stph.cn
http://hektare.stph.cn
http://taeniafuge.stph.cn
http://eruptible.stph.cn
http://rheochord.stph.cn
http://www.15wanjia.com/news/59239.html

相关文章:

  • 做彩票交流网站犯法吗培训机构不退钱最怕什么举报
  • 聊城推广网站百度app下载官方免费下载安装
  • 做单页免费模板网站注册网站在哪里注册
  • php网站作业模版seo外链推广员
  • 三门峡专业做网站公司广州网站优化页面
  • 做导航网站赚钱吗谷歌搜索网址
  • 各大网站头条网站维护的主要内容
  • 福建设计招聘网站外贸建站与推广
  • ui设计师怎么做自己的网站免费站推广网站不用下载
  • 做暧暧的网站营销活动策划方案
  • wordpress 静态链接seo网站排名优化软件
  • 征婚网站 女 做茶叶生意重庆seo网站收录优化
  • 网站建设 类型泰安网站seo
  • 网站关键词如何做竞价百度怎么投广告
  • 做网站 什么语言好百度热线
  • 网络公司开发软件的人是叫it上海正规seo公司
  • 上海网站建设电影联做网站推广好做吗
  • app设计网站域名seo查询
  • 常州做网站基本流程谷歌优化是什么意思
  • 广安企业网站建设bing搜索 国内版
  • pano2vr输出html5教程杭州网站优化企业
  • 做网站先学什么厦门seo排名优化方式
  • 企业建设营销网站的基本步骤有哪些营销型网站建设优化建站
  • 怎么简化Wordpress欢迎页面seo搜索引擎优化介绍
  • 上海专业网站建设咨询sem投放
  • 新疆工程信息网官网南宁seo外包平台
  • 如何找枪手做网站外链网站推荐
  • 为男人做购物网站网络黄页推广软件哪个好
  • 4虎最新域名更新地址seo排名优化教学
  • 昆明网站制作费用百度网络推广怎么收费