Skip to content

Commit 6cebf27

Browse files
Update aima.py
1 parent 472089a commit 6cebf27

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

aima.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: UTF-8 -*-
21
import json
32
import _json
43
import sys
@@ -10,7 +9,7 @@
109

1110
#创建excel
1211
book = xlwt.Workbook(encoding='utf-8',style_compression=0)
13-
12+
#根据爱玛电动车在前端写死的select里,找出规则,按顺序排列
1413
cityList = [
1514

1615
"北京",
@@ -45,22 +44,32 @@
4544
"浙江",
4645
"重庆"
4746
]
48-
47+
#定义book,创建sheet
48+
sheet = book.add_sheet('list', cell_overwrite_ok=True)
49+
count = 0
4950
for i in range(2,33):
5051
info = requests.get("https://www.aimatech.com/outlets/list?ccode=0&pcode=%s"%(i))
5152
jsonall = json.loads(info.text[11:-1])
52-
sheet = book.add_sheet('list', cell_overwrite_ok=True)
53+
5354
print("已经写完第一条数据,进入第二条")
5455
# 写入表头,定义好列
55-
sheet.write(0, 0, label='门店地址')
56-
sheet.write(0, 1, label='门店名字')
57-
sheet.write(0, 2, label='联系电话')
56+
sheet.write(0, 0, label='城市名字')
57+
sheet.write(0, 1, label='门店地址')
58+
sheet.write(0, 2, label='门店名字')
59+
sheet.write(0, 3, label='联系电话')
5860
# print(jsonall)
5961
for a in jsonall:
60-
print(i)
6162
# 添加sheet
6263
addr = a['addr']
6364
name = a['realname']
6465
phonenumber = a['mobile']
6566

66-
book.save('/Users/qiao/爱玛电动车所有门店信息.xls')
67+
68+
count = count + 1
69+
70+
sheet.write(count, 0, cityList[i-2])
71+
sheet.write(count, 1, addr)
72+
sheet.write(count, 2, name)
73+
sheet.write(count, 3, phonenumber)
74+
75+
book.save('D:\Python_files\爱玛电动车所有门店信息.xls')

0 commit comments

Comments
 (0)