import xlrd
data
=xlrd
.open_workbook
(r
'C:\Users\71978\Desktop\文件\错误数据\亚马逊信息02.xlsx')
data
.sheet_loaded
(0)
data
.unload_sheet
(0)
print(data
.sheets
())
print(data
.sheets
()[0])
print(data
.sheet_by_index
(0))
print(data
.sheet_by_name
('亚马逊商品信息'))
print(data
.sheet_names
())
print(data
.nsheets
)
sheet
=data
.sheet_by_index
(0)
print(sheet
.nrows
)
print(sheet
.row
(0))
print(sheet
.row_types
(1))
print(sheet
.row
(1)[2].value
)
print(sheet
.row_values
(1))
print(sheet
.row_len
(1))
sheet
=data
.sheet_by_index
(0)
print(sheet
.ncols
)
print(sheet
.col
(1))
print(sheet
.col
(1)[2].value
)
print(sheet
.col_values
(1))
print(sheet
.col_types
(2))
sheet
=data
.sheet_by_index
(0)
print(sheet
.cell
(1,2))
print(sheet
.cell_type
(1,2))
print(sheet
.cell
(1,2).ctype
)
print(sheet
.cell
(1,2).value
)
print(sheet
.cell_value
(1,2))
import xlwt
titlestyle
=xlwt
.XFStyle
()
titlefont
=xlwt
.Font
()
titlefont
.name
="黑体"
titlefont
.bold
=True
titlefont
.height
=24*20
titlefont
.colour_index
=0x08
titlestyle
.font
=titlefont
cellalign
=xlwt
.Alignment
()
cellalign
.horz
=0x02
cellalign
.vert
=0x01
titlestyle
.alignment
=cellalign
borders
=xlwt
.Borders
()
borders
.right
=xlwt
.Borders
.DASHED
borders
.bottom
=xlwt
.Borders
.DASHED
titlestyle
.borders
=borders
datestyle
=xlwt
.XFStyle
()
bgcolor
=xlwt
.Pattern
()
bgcolor
.pattern
=xlwt
.Pattern
.SOLID_PATTERN
bgcolor
.pattern_fore_colour
=22
datestyle
.pattern
=bgcolor
'''
使用xlwt模块流程
1.创建工作簿
2.创建工作表
3.填充工作表内容
4.保存文件
'''
wb
=xlwt
.Workbook
()
ws
=wb
.add_sheet
('亚马逊商城信息')
ws
.write_merge
(0,0,0,9,'爬取的亚马逊商品信息',titlestyle
)
data
=(('产品标题','评分','产品售价','品牌','售方','卖方','产品ASIN','大排名','小排名','产品链接'),
('Beckham ','35623','In Stock.','Visit','Amazon','Thalestris','B01LYNW421','#16 in Home & Kitchen' ,'#1 in Bed Pillows' ,"https://www.amazon.com/"))
for i
,itme
in enumerate(data
):
print('写入第%d行'%i
)
for j
,val
in enumerate(itme
):
ws
.write
(i
+1,j
,val
,datestyle
)
wsimage
=wb
.add_sheet
('图片')
wb
.save
(r
'C:\Users\71978\Desktop\文件\错误数据\亚马逊爬取的资料.xls')
以上是我边看视频边抄的代码,同时分享给大家,也是给自己留存使用 视频链接:https://www.bilibili.com/video/BV14p4y1e7RK?from=search&seid=8292456772443502901
欢迎加入python数据分析、爬虫学习讨论群,一起自学一起进步。