In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how Python crawls Gaode map subway line and station data. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
preface
The text and pictures of this article come from the network, only for learning and communication, and do not have any commercial use. The copyright belongs to the original author. If you have any questions, please contact us in time for processing.
# coding=utf-8import requestsimport timeimport jsonimport astimport osimport utilsfrom lxml import etreePAGE_URL = 'http://map.amap.com/subway/index.html?& 1100'DATA_URL = 'http://map.amap.com/service/subway? srhdata='HEADER = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"}def fetchAllCity(url, header): r = requests.get(url, header) html = r.content element = etree.HTML(html) options = element.xpath("//a[contains(@class, 'city')]") cities = [] for option in options: city = { 'id': option.get('id'), 'name': option.get('cityname'), 'text': option.text } cities.append(city) return citiesdef parseCityData(citys): lw = open('./ lwkt.txt', 'w') lw.write('wkt' + '\n') pw = open('./ pwkt.txt', 'w') pw.write('wkt' + '\n') for city in citys: parseCityPointFromApi(city, lw, pw)def parseCityPointFromApi(city, lw, pw): url = DATA_URL + "{}_drw_{}.json".format(city['id'], city['name']) print(url) json_str = requests.get(url).text res = json.loads(json_str) res = res['l'] for r in res: st = r['st'] coords = [] for s in st: _coords = s.get('sl', '').split(',') coords.append(_coords) pwkt = '"POINT ({} {})"'.format(_coords[0], _coords[1]) pw.write(pwkt + '\n') new_coords = ','.join(['%s %s' % (coord[0], coord[1]) for coord in coords]) lwkt = '"LINESTRING(%s)"' % new_coords lw.write(lwkt + '\n')def main(): cities = fetchAllCity(PAGE_URL, HEADER) print(cities) parseCityData(cities)if __name__ == '__main__': main() Thank you for reading! About "Python how to crawl Gaode map subway line and site data" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.