Python实现信息自动配对爬虫排版程序( 三 )

根据Excel表格单元填充进拼音:
for i in range(len(col0)): sht.row_dimensions[i].height = 150.0 if isinstance(col0[i], float): sheet["G"+str(i+1)].value=https://www.isolves.com/it/cxkf/yy/Python/2020-07-22/yin[i] 接着根据已经保存下来的爬取到的图片依次按照布局
顺序进行填充 , 同时还要设定一定的图片尺寸 , 以保
证布局的美观和合理:
for i in os.listdir("image"): for j in os.listdir("image/"+i): tw="image/"+i+"/"+j label=j.split(".") label=label[0] 根据label对象的数据判断对应序号 , 根据序号判断对
应图片存放的文件夹位置 , 然后读取图片并复制到
Excel表格中:
if int(label)==1: try: img_address_2 = "image/" +i+"/"+ str(label) + '.jpg' 使用openpyxl中的image函数读取图片
  img = Image(img_address_2)设置图片的长宽为200 , 统一尺寸以方便布局
img.width = 200.0 img.height = 200.0 通过单元格添加图片即可达到插入图片的效果
  sht.add_image(img, 'J'+str(int(i)+1))如果没有合理的找到对应图片就跳过:
except: pass if int(label)==2: try: img_address_2 = "image/" +i+"/"+ str(label) + '.jpg' img = Image(img_address_2) img.width = 200.0 img.height = 200.0 sht.add_image(img, 'M'+str(int(i)+1)) except: pass if int(label)==3: try: img_address_2 = "image/" +i+"/"+ str(label) + '.jpg' img = Image(img_address_2) img.width = 200.0 img.height = 200.0 sht.add_image(img, 'P'+str(int(i)+1)) except: pass if int(label)==4: try: img_address_2 = "image/" +i+"/"+ str(label) + '.jpg' img = Image(img_address_2) img.width = 200.0 img.height = 200.0 sht.add_image(img, 'S'+str(int(i)+1)) except: passwb.save("dels.xlsx") 最终得到的排版程序如下可见:
 

Python实现信息自动配对爬虫排版程序

文章插图
由此可见通过python的office操作和网络搜索自动爬
取排版可以极大地节省人力和时间 。
作者介绍:
李秋键 , CSDN 博客专家 , CSDN达人课作者 。硕士在读于中国矿业大学 , 开发有taptapAndroid/ target=_blank class=infotextkey>安卓武侠游戏一部 , vip视频解析 , 文意转换工具 , 写作机器人等项目 , 发表论文若干 , 多次高数竞赛获奖等等 。
源码地址:
链接:
https://pan.baidu.com/s/1Rtl3zoQRhKeRstgnl1firw
提取码:wk2z




推荐阅读