老板们,你们每天上班的代步工具是什么呢?我每天上下班要换乘三班地铁,今天上班摸鱼就想着绘制一下所在城市的地铁线路图,有兴趣的小老板们一起先来看看效果图吧!
获取数据
1.首先我们打开高德地图的地铁网页如下:
http://map.amap.com/subway/index.html?&1100
2. 获取到的是一个json数据集,可以看到我们想要获取的数据就是每一个地铁站的坐标,也就是图中的sl标签下的数据。
3. 我们先是用爬虫将所有的坐标打印出来。
url = 'http://map.amap.com/service/subway?_1620623429768&srhdata=6101_drw_xian.json'
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4484.7 Safari/537.36',
'Referer':'http://map.amap.com/subway/index.html?&1100',
'Cookie':'UM_distinctid=17954ac8d5e5e-0ac20e2913b1e6-71153641-1fa400-17954ac8d5f7ba; CNZZDATA1255672570=1041388408-1620620633-%7C1620620633; connect.sess=s%3Aj%3A%7B%7D.DffclZ%2FN%2BAiqU5kXMjqg3VQHapScLmBFjbTUDpqgPVQ'
}
resp = requests.get(url, headers).json()
stations = []
for i in resp['l']:
station = []
for a in i['st']:
station.append([float(b) for b in a['sl'].split(',')])
stations.append(station)
print('高德地图坐标:',stations)
'''
高德地图部分坐标: [[[108.753079, 34.320229], [108.763291, 34.317347], [108.777618, 34.313193], [108.79676, 34.307257], [108.813536, 34.300164], [108.832212, 34.289958], [108.85242, 34.284382], [108.862601, 34.279195], [108.873971, 34.273042],