感兴趣的可以看我的另一篇博客:一次完整的爬虫
解释:
import xlwt
# 创建一个workbook
workbook = xlwt.Workbook(encoding='utf-8')
# 创建表名
data_sheet = workbook.add_sheet('sheet1')
# 设置表头
row0 = ['1', '2', '3', '4', '5', '6']
# 将第一行写进去
for k in range(0, len(row0)):
data_sheet.write(0, k, row0[k])
# 利用cnt控制行数
cnt = 1
# 写入全部数据
for item in all_url:
list_informations = []
list_informations += get_information(item)
for j in range(0, len(list_informations)):
data_sheet.write(cnt, j, list_informations[j])
cnt += 1
# 保存文件
workbook.save('filename.xlsx')