废话不多说,直接上代码~!
def shop_csv():
goods = Model('goods')
data = goods.select1()
# 1. 创建文件对象
# f = open('2万家纺商品数据.csv', 'wb', encoding='utf-8')
f = open('2万家纺商品数据.csv', 'w', encoding='utf-8', newline='' "")
# 2. 基于文件对象构建 csv写入对象
csv_writer = csv.writer(f)
# 3. 构建列表头
csv_writer.writerow(["序列号", "链接", "上架日期"])
num = 0
for ii in data:
num+= 1
# print(num)
# 4. 写入csv文件内容
csv_writer.writerow([num, ii[0], ii[1]])
#
# # 5. 关闭文件
f.close()
处理excel空行问题用
f = open('2万家纺商品数据.csv', 'w', encoding='utf-8', newline='' "")
希望对大家有帮助!