日常Excel处理

日常Excel处理以及图片自动下载

import requests   
import os

mf=open("wc-product-export-15-8-2020-1597477111016.csv","r")
content=mf.readlines()
first=True
out=open("out.csv","w")
for line in content:
    if first:
        first=False
        out.write(line)
        continue
    all_in=line.strip().split(",")
    
    if all_in[3]!="":
        all_in[3]=str(int(int(all_in[3])/0.8))
    if all_in[4]!="":
        all_in[4]=str(int(int(all_in[4])/0.8))
    if all_in[6]!="":
        os.mkdir("pic/"+all_in[0]+"_"+all_in[2].replace(" ","_"))
        all_pic=all_in[6].strip('"').split(",")
        i=0
        for url in all_pic:
            i+=1
            print(url)
            r = requests.get(url,verify=False)
            with open("pic/"+all_in[0]+"_"+all_in[2].replace(" ","_")+"/"+str(i)+".png", 'wb') as f:
                f.write(r.content)  
    print(all_in[0],"done")

    print(all_in)
    out_string=",".join(all_in)+"\n"
    out.write(out_string)

 

发表评论

邮箱地址不会被公开。 必填项已用*标注