1
- # -*- coding: UTF-8 -*-
2
1
import json
3
2
import _json
4
3
import sys
10
9
11
10
#创建excel
12
11
book = xlwt .Workbook (encoding = 'utf-8' ,style_compression = 0 )
13
-
12
+ #根据爱玛电动车在前端写死的select里,找出规则,按顺序排列
14
13
cityList = [
15
14
16
15
"北京" ,
45
44
"浙江" ,
46
45
"重庆"
47
46
]
48
-
47
+ #定义book,创建sheet
48
+ sheet = book .add_sheet ('list' , cell_overwrite_ok = True )
49
+ count = 0
49
50
for i in range (2 ,33 ):
50
51
info = requests .get ("https://www.aimatech.com/outlets/list?ccode=0&pcode=%s" % (i ))
51
52
jsonall = json .loads (info .text [11 :- 1 ])
52
- sheet = book . add_sheet ( 'list' , cell_overwrite_ok = True )
53
+
53
54
print ("已经写完第一条数据,进入第二条" )
54
55
# 写入表头,定义好列
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 = '联系电话' )
58
60
# print(jsonall)
59
61
for a in jsonall :
60
- print (i )
61
62
# 添加sheet
62
63
addr = a ['addr' ]
63
64
name = a ['realname' ]
64
65
phonenumber = a ['mobile' ]
65
66
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