使用python抓取高德地图城市信息
基于高德地图的API和Python的实现,
# -*- coding: utf-8 -*- #encoding=utf-8 import urllib2 import sys, json from StringIO import StringIO import gzip import MySQLdb import datetime reload(sys) sys.setdefaultencoding('utf-8') provinceList = ['北京市', '天津市', '河北省', '山西省', '内蒙古自治区', '辽宁省', '吉林省','黑龙江省', '上海市', '江苏省', '浙江省', '安徽省', '福建省', '江西省', '山东省','河南省', '湖北省', '湖南省', '广东省', '广西壮族自治区', '海南省', '重庆市','四川省', '贵州省', '云南省', '西藏自治区', '陕西省', '甘肃省', '青海省', '宁夏回族自治区', '新疆维吾尔自治区', '台灣', '香港特别行>政区', '澳门特别行政区'] send_headers = { 'Accept':'*/*', 'Accept-Encoding':'gzip, deflate, sdch', 'Accept-Language':'zh-CN,zh;q=0.8', 'Connection':'keep-alive', 'Host':'restapi.amap.com', 'Referer':'http://lbs.amap.com/fn/iframe/?id=3556', } def getCity(province): print "Province->" + province url = "http://restapi.amap.com/v3/config/district?subdistrict=1&extensions=all&level=province&key=608d75903d29ad471362f8c58c550daf&s=rsv3&output=json&callback=jsonp_" + getJsonP() + "_&keywords=" + province; data = getData(url) item = data['districts'][0]; if item['citycode'] == []: item['citycode'] = '' save([item['citycode'], item['adcode'], item['name'], item['center'], item['level'], '']) for item in data['districts'][0]['districts']: save([item['citycode'], item['adcode'], item['name'], item['center'], item['level'], '']) while 1: try: getDistrict(item) break except Exception, e: print 'retry:' + item['name'] + "->" + str(e) def getCity1(province): #print "Province->" + province url = "http://restapi.amap.com/v3/config/district?subdistrict=1&extensions=all&level=province&key=608d75903d29ad471362f8c58c550daf&s=rsv3&output=json&callback=jsonp_" + getJsonP() + "_&keywords=" + province; data = getData(url) if data['districts'] == []: return item = data['districts'][0]; if item['citycode'] == []: item['citycode'] = '' save([item['citycode'], item['adcode'], item['name'], item['center'], item['level'], '']) for item in data['districts'][0]['districts']: if item['citycode'] == []: item['citycode'] = '' save([item['citycode'], item['adcode'], item['name'], item['center'], item['level'], '']) def getCity2(province): #print "Province->" + province url = "http://restapi.amap.com/v3/config/district?subdistrict=1&extensions=all&level=province&key=608d75903d29ad471362f8c58c550daf&s=rsv3&output=json&callback=jsonp_" + getJsonP() + "_&keywords=" + province; data = getData(url) if data['districts'] == []: return item = data['districts'][0]; if item['citycode'] == []: item['citycode'] = '' #save([item['citycode'], item['adcode'], item['name'], item['center'], item['level'], '']) for item in data['districts'][0]['districts']: if item['citycode'] == []: item['citycode'] = '' ##save([item['citycode'], item['adcode'], item['name'], item['center'], item['level'], '']) print '"%s","%s"' %(province,item['name']) jsonp = 9999 def getJsonP(): global jsonp jsonp = jsonp + 1 if (jsonp > 99999): jsonp = 10000 return str(jsonp) def getDataWithEx(url): req = urllib2.Request(url,headers=send_headers) r = urllib2.urlopen(req,timeout=30) if r.info().get('Content-Encoding') == 'gzip': buf = StringIO(r.read()) f = gzip.GzipFile(fileobj=buf) data = f.read() else: data = r.read() return json.loads(data[13:-1]) def getData(url): while 1: try: response = getDataWithEx(url) break except Exception, e: print 'retry:' + url + " with error " + str(e) return response def save1(value): print "insert into amap(citycode, adcode, name, center, level, areacode) values(%s);" % ', '.join(value) def save(value): try: conn=MySQLdb.connect(host='localhost',user='root',port=3306,charset="utf8") conn.select_db('base') cur=conn.cursor() cur.execute("insert into amap(citycode, adcode, name, center, level, areacode) values(%s,%s,%s,%s,%s,%s)",value) conn.commit() cur.close() conn.close() except MySQLdb.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1]) print value def getDistrict(city): print "->City->" + city['name'] url = "http://restapi.amap.com/v3/config/district?subdistrict=1&extensions=all&level=city&key=608d75903d29ad471362f8c58c550daf&s=rsv3&output=json&callback=jsonp_" + getJsonP() + "_&keywords=" + city['name'] data = getData(url) for possible in data['districts']: if possible['adcode'] == city['adcode']: for item in possible['districts']: save([item['citycode'], item['adcode'], item['name'], item['center'], item['level'], '']) while 1: try: getBusiness(item) break except Exception, e: print 'retry:' + item['name'] + "->" + str(e) break def getBusiness(district): print "->->District->" + district['name'] url = "http://restapi.amap.com/v3/config/district?subdistrict=1&extensions=all&level=district&key=608d75903d29ad471362f8c58c550daf&s=rsv3&output=json&callback=jsonp_" + getJsonP() + "_&keywords=" + district['name'] data = getData(url) for possible in data['districts']: if possible['adcode'] == district['adcode']: values=[] for item in possible['districts']: values.append((item['citycode'], item['adcode'], item['name'], item['center'], item['level'], item['areacode'])) saveAll(values) break def saveAll(values): try: conn=MySQLdb.connect(host='www.xxx.com',user='xxx',passwd='xxx',port=3306,charset="utf8") conn.select_db('test') cur=conn.cursor() cur.executemany("insert into amap(citycode, adcode, name, center, level, areacode) values(%s,%s,%s,%s,%s,%s)",values) conn.commit() cur.close() conn.close() except MySQLdb.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1]) starttime = datetime.datetime.now() for province in provinceList: getCity1(province) print 'over' endtime = datetime.datetime.now() print (endtime - starttime).seconds
- amap_dump.sql
-- MySQL dump 10.13 Distrib 5.5.46, for debian-linux-gnu (x86_64) -- -- Host: 0.0.0.0 Database: base -- ------------------------------------------------------ -- Server version 5.5.46-0ubuntu0.14.04.2 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `amap` -- DROP TABLE IF EXISTS `amap`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `amap` ( `id` int(11) NOT NULL AUTO_INCREMENT, `citycode` varchar(10) NOT NULL DEFAULT '', `adcode` varchar(20) NOT NULL DEFAULT '', `name` varchar(20) NOT NULL DEFAULT '', `center` varchar(50) NOT NULL DEFAULT '', `level` varchar(10) NOT NULL DEFAULT '', `areacode` varchar(20) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1633 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `amap` -- LOCK TABLES `amap` WRITE; /*!40000 ALTER TABLE `amap` DISABLE KEYS */; INSERT INTO `amap` VALUES (1224,'010','110000','北京市','116.405285,39.904989','province',''),(1225,'010','110100','北京市市辖区','116.405285,39.904989','city',''),(1226,'022','120000','天津市','117.190182,39.125596','province',''),(1227,'022','120100','天津市市辖区','117.190182,39.125596','city',''),(1228,'022','120200','天津市郊县','117.824898,39.330613','city',''),(1229,'','130000','河北省','114.502461,38.045474','province',''),(1230,'0311','130100','石家庄市','114.502461,38.045474','city',''),(1231,'0315','130200','唐山市','118.175393,39.635113','city',''),(1232,'0335','130300','秦皇岛市','119.586579,39.942531','city',''),(1233,'0310','130400','邯郸市','114.490686,36.612273','city',''),(1234,'0319','130500','邢台市','114.508851,37.0682','city',''),(1235,'0312','130600','保定市','115.482331,38.867657','city',''),(1236,'0313','130700','张家口市','114.884091,40.811901','city',''),(1237,'0314','130800','承德市','117.939152,40.976204','city',''),(1238,'0317','130900','沧州市','116.857461,38.310582','city',''),(1239,'0316','131000','廊坊市','116.704441,39.523927','city',''),(1240,'0318','131100','衡水市','115.665993,37.735097','city',''),(1241,'','140000','山西省','112.549248,37.857014','province',''),(1242,'0351','140100','太原市','112.549248,37.857014','city',''),(1243,'0352','140200','大同市','113.295259,40.09031','city',''),(1244,'0353','140300','阳泉市','113.583285,37.861188','city',''),(1245,'0355','140400','长治市','113.113556,36.191112','city',''),(1246,'0356','140500','晋城市','112.851274,35.497553','city',''),(1247,'0349','140600','朔州市','112.433387,39.331261','city',''),(1248,'0354','140700','晋中市','112.736465,37.696495','city',''),(1249,'0359','140800','运城市','111.003957,35.022778','city',''),(1250,'0350','140900','忻州市','112.733538,38.41769','city',''),(1251,'0357','141000','临汾市','111.517973,36.08415','city',''),(1252,'0358','141100','吕梁市','111.134335,37.524366','city',''),(1253,'','150000','内蒙古自治区','111.670801,40.818311','province',''),(1254,'0471','150100','呼和浩特市','111.670801,40.818311','city',''),(1255,'0472','150200','包头市','109.840405,40.658168','city',''),(1256,'0473','150300','乌海市','106.825563,39.673734','city',''),(1257,'0476','150400','赤峰市','118.956806,42.275317','city',''),(1258,'0475','150500','通辽市','122.263119,43.617429','city',''),(1259,'0477','150600','鄂尔多斯市','109.99029,39.817179','city',''),(1260,'0470','150700','呼伦贝尔市','119.758168,49.215333','city',''),(1261,'0478','150800','巴彦淖尔市','107.416959,40.757402','city',''),(1262,'0474','150900','乌兰察布市','113.114543,41.034126','city',''),(1263,'0482','152200','兴安盟','122.070317,46.076268','city',''),(1264,'0479','152500','锡林郭勒盟','116.090996,43.944018','city',''),(1265,'0483','152900','阿拉善盟','105.706422,38.844814','city',''),(1266,'','210000','辽宁省','123.429096,41.796767','province',''),(1267,'024','210100','沈阳市','123.429096,41.796767','city',''),(1268,'0411','210200','大连市','121.618622,38.91459','city',''),(1269,'0412','210300','鞍山市','122.995632,41.110626','city',''),(1270,'024','210400','抚顺市','123.921109,41.875956','city',''),(1271,'024','210500','本溪市','123.770519,41.297909','city',''),(1272,'0415','210600','丹东市','124.383044,40.124296','city',''),(1273,'0416','210700','锦州市','121.135742,41.119269','city',''),(1274,'0417','210800','营口市','122.235151,40.667432','city',''),(1275,'0418','210900','阜新市','121.648962,42.011796','city',''),(1276,'0419','211000','辽阳市','123.18152,41.269402','city',''),(1277,'0427','211100','盘锦市','122.06957,41.124484','city',''),(1278,'024','211200','铁岭市','123.844279,42.290585','city',''),(1279,'0421','211300','朝阳市','120.451176,41.576758','city',''),(1280,'0429','211400','葫芦岛市','120.856394,40.755572','city',''),(1281,'','220000','吉林省','125.3245,43.886841','province',''),(1282,'0431','220100','长春市','125.3245,43.886841','city',''),(1283,'0432','220200','吉林市','126.55302,43.843577','city',''),(1284,'0434','220300','四平市','124.370785,43.170344','city',''),(1285,'0437','220400','辽源市','125.145349,42.902692','city',''),(1286,'0435','220500','通化市','125.936501,41.721177','city',''),(1287,'0439','220600','白山市','126.427839,41.942505','city',''),(1288,'0438','220700','松原市','124.823608,45.118243','city',''),(1289,'0436','220800','白城市','122.841114,45.619026','city',''),(1290,'0433','222400','延边朝鲜族自治州','129.513228,42.904823','city',''),(1291,'','230000','黑龙江省','126.642464,45.756967','province',''),(1292,'0451','230100','哈尔滨市','126.642464,45.756967','city',''),(1293,'0452','230200','齐齐哈尔市','123.95792,47.342081','city',''),(1294,'0467','230300','鸡西市','130.975966,45.300046','city',''),(1295,'0468','230400','鹤岗市','130.277487,47.332085','city',''),(1296,'0469','230500','双鸭山市','131.157304,46.643442','city',''),(1297,'0459','230600','大庆市','125.11272,46.590734','city',''),(1298,'0458','230700','伊春市','128.899396,47.724775','city',''),(1299,'0454','230800','佳木斯市','130.361634,46.809606','city',''),(1300,'0464','230900','七台河市','131.015584,45.771266','city',''),(1301,'0453','231000','牡丹江市','129.618602,44.582962','city',''),(1302,'0456','231100','黑河市','127.499023,50.249585','city',''),(1303,'0455','231200','绥化市','126.99293,46.637393','city',''),(1304,'0457','232700','大兴安岭地区','124.711526,52.335262','city',''),(1305,'021','310000','上海市','121.472644,31.231706','province',''),(1306,'021','310100','上海市市辖区','121.472644,31.231706','city',''),(1307,'021','310200','上海市郊县','121.397417,31.623587','city',''),(1308,'','320000','江苏省','118.767413,32.041544','province',''),(1309,'025','320100','南京市','118.767413,32.041544','city',''),(1310,'0510','320200','无锡市','120.301663,31.574729','city',''),(1311,'0516','320300','徐州市','117.184811,34.261792','city',''),(1312,'0519','320400','常州市','119.946973,31.772752','city',''),(1313,'0512','320500','苏州市','120.619585,31.299379','city',''),(1314,'0513','320600','南通市','120.864608,32.016212','city',''),(1315,'0518','320700','连云港市','119.178821,34.600018','city',''),(1316,'0517','320800','淮安市','119.021265,33.597506','city',''),(1317,'0515','320900','盐城市','120.139998,33.377631','city',''),(1318,'0514','321000','扬州市','119.421003,32.393159','city',''),(1319,'0511','321100','镇江市','119.452753,32.204402','city',''),(1320,'0523','321200','泰州市','119.915176,32.484882','city',''),(1321,'0527','321300','宿迁市','118.275162,33.963008','city',''),(1322,'','330000','浙江省','120.153576,30.287459','province',''),(1323,'0571','330100','杭州市','120.153576,30.287459','city',''),(1324,'0574','330200','宁波市','121.549792,29.868388','city',''),(1325,'0577','330300','温州市','120.672111,28.000575','city',''),(1326,'0573','330400','嘉兴市','120.750865,30.762653','city',''),(1327,'0572','330500','湖州市','120.102398,30.867198','city',''),(1328,'0575','330600','绍兴市','120.582112,29.997117','city',''),(1329,'0579','330700','金华市','119.649506,29.089524','city',''),(1330,'0570','330800','衢州市','118.87263,28.941708','city',''),(1331,'0580','330900','舟山市','122.106863,30.016028','city',''),(1332,'0576','331000','台州市','121.428599,28.661378','city',''),(1333,'0578','331100','丽水市','119.921786,28.451993','city',''),(1334,'','340000','安徽省','117.283042,31.86119','province',''),(1335,'0551','340100','合肥市','117.283042,31.86119','city',''),(1336,'0553','340200','芜湖市','118.376451,31.326319','city',''),(1337,'0552','340300','蚌埠市','117.363228,32.939667','city',''),(1338,'0554','340400','淮南市','117.018329,32.647574','city',''),(1339,'0555','340500','马鞍山市','118.507906,31.689362','city',''),(1340,'0561','340600','淮北市','116.794664,33.971707','city',''),(1341,'0562','340700','铜陵市','117.816576,30.929935','city',''),(1342,'0556','340800','安庆市','117.043551,30.50883','city',''),(1343,'0559','341000','黄山市','118.317325,29.709239','city',''),(1344,'0550','341100','滁州市','118.316264,32.303627','city',''),(1345,'0558','341200','阜阳市','115.819729,32.896969','city',''),(1346,'0557','341300','宿州市','116.984084,33.633891','city',''),(1347,'0564','341500','六安市','116.507676,31.752889','city',''),(1348,'0558','341600','亳州市','115.782939,33.869338','city',''),(1349,'0566','341700','池州市','117.489157,30.656037','city',''),(1350,'0563','341800','宣城市','118.757995,30.945667','city',''),(1351,'','350000','福建省','119.306239,26.075302','province',''),(1352,'0591','350100','福州市','119.306239,26.075302','city',''),(1353,'0592','350200','厦门市','118.11022,24.490474','city',''),(1354,'0594','350300','莆田市','119.007558,25.431011','city',''),(1355,'0598','350400','三明市','117.635001,26.265444','city',''),(1356,'0595','350500','泉州市','118.589421,24.908853','city',''),(1357,'0596','350600','漳州市','117.661801,24.510897','city',''),(1358,'0599','350700','南平市','118.178459,26.635627','city',''),(1359,'0597','350800','龙岩市','117.02978,25.091603','city',''),(1360,'0593','350900','宁德市','119.527082,26.65924','city',''),(1361,'','360000','江西省','115.892151,28.676493','province',''),(1362,'0791','360100','南昌市','115.892151,28.676493','city',''),(1363,'0798','360200','景德镇市','117.214664,29.29256','city',''),(1364,'0799','360300','萍乡市','113.852186,27.622946','city',''),(1365,'0792','360400','九江市','115.992811,29.712034','city',''),(1366,'0790','360500','新余市','114.930835,27.810834','city',''),(1367,'0701','360600','鹰潭市','117.033838,28.238638','city',''),(1368,'0797','360700','赣州市','114.940278,25.85097','city',''),(1369,'0796','360800','吉安市','114.986373,27.111699','city',''),(1370,'0795','360900','宜春市','114.391136,27.8043','city',''),(1371,'0794','361000','抚州市','116.358351,27.98385','city',''),(1372,'0793','361100','上饶市','117.971185,28.44442','city',''),(1373,'','370000','山东省','117.000923,36.675807','province',''),(1374,'0531','370100','济南市','117.000923,36.675807','city',''),(1375,'0532','370200','青岛市','120.355173,36.082982','city',''),(1376,'0533','370300','淄博市','118.047648,36.814939','city',''),(1377,'0632','370400','枣庄市','117.557964,34.856424','city',''),(1378,'0546','370500','东营市','118.66471,37.434564','city',''),(1379,'0535','370600','烟台市','121.391382,37.539297','city',''),(1380,'0536','370700','潍坊市','119.107078,36.70925','city',''),(1381,'0537','370800','济宁市','116.587245,35.415393','city',''),(1382,'0538','370900','泰安市','117.129063,36.194968','city',''),(1383,'0631','371000','威海市','122.116394,37.509691','city',''),(1384,'0633','371100','日照市','119.461208,35.428588','city',''),(1385,'0634','371200','莱芜市','117.677736,36.214397','city',''),(1386,'0539','371300','临沂市','118.326443,35.065282','city',''),(1387,'0534','371400','德州市','116.307428,37.453968','city',''),(1388,'0635','371500','聊城市','115.980367,36.456013','city',''),(1389,'0543','371600','滨州市','118.016974,37.383542','city',''),(1390,'0530','371700','菏泽市','115.469381,35.246531','city',''),(1391,'','410000','河南省','113.665412,34.757975','province',''),(1392,'0371','410100','郑州市','113.665412,34.757975','city',''),(1393,'0371','410200','开封市','114.341447,34.797049','city',''),(1394,'0379','410300','洛阳市','112.434468,34.663041','city',''),(1395,'0375','410400','平顶山市','113.307718,33.735241','city',''),(1396,'0372','410500','安阳市','114.352482,36.103442','city',''),(1397,'0392','410600','鹤壁市','114.295444,35.748236','city',''),(1398,'0373','410700','新乡市','113.883991,35.302616','city',''),(1399,'0391','410800','焦作市','113.238266,35.23904','city',''),(1400,'0393','410900','濮阳市','115.041299,35.768234','city',''),(1401,'0374','411000','许昌市','113.826063,34.022956','city',''),(1402,'0395','411100','漯河市','114.026405,33.575855','city',''),(1403,'0398','411200','三门峡市','111.194099,34.777338','city',''),(1404,'0377','411300','南阳市','112.540918,32.999082','city',''),(1405,'0370','411400','商丘市','115.650497,34.437054','city',''),(1406,'0376','411500','信阳市','114.075031,32.123274','city',''),(1407,'0394','411600','周口市','114.649653,33.620357','city',''),(1408,'0396','411700','驻马店市','114.024736,32.980169','city',''),(1409,'0391','419001','济源市','112.590047,35.090378','city',''),(1410,'','420000','湖北省','114.298572,30.584355','province',''),(1411,'027','420100','武汉市','114.298572,30.584355','city',''),(1412,'0714','420200','黄石市','115.077048,30.220074','city',''),(1413,'0719','420300','十堰市','110.787916,32.646907','city',''),(1414,'0717','420500','宜昌市','111.290843,30.702636','city',''),(1415,'0710','420600','襄阳市','112.144146,32.042426','city',''),(1416,'0711','420700','鄂州市','114.890593,30.396536','city',''),(1417,'0724','420800','荆门市','112.204251,31.03542','city',''),(1418,'0712','420900','孝感市','113.926655,30.926423','city',''),(1419,'0716','421000','荆州市','112.23813,30.326857','city',''),(1420,'0713','421100','黄冈市','114.879365,30.447711','city',''),(1421,'0715','421200','咸宁市','114.328963,29.832798','city',''),(1422,'0722','421300','随州市','113.37377,31.717497','city',''),(1423,'0718','422800','恩施土家族苗族自治州','109.48699,30.283114','city',''),(1424,'0728','429004','仙桃市','113.453974,30.364953','city',''),(1425,'0728','429005','潜江市','112.896866,30.421215','city',''),(1426,'0728','429006','天门市','113.165862,30.653061','city',''),(1427,'0719','429021','神农架林区','110.671525,31.744449','city',''),(1428,'','430000','湖南省','112.982279,28.19409','province',''),(1429,'0731','430100','长沙市','112.982279,28.19409','city',''),(1430,'0731','430200','株洲市','113.151737,27.835806','city',''),(1431,'0731','430300','湘潭市','112.944052,27.82973','city',''),(1432,'0734','430400','衡阳市','112.607693,26.900358','city',''),(1433,'0739','430500','邵阳市','111.46923,27.237842','city',''),(1434,'0730','430600','岳阳市','113.132855,29.37029','city',''),(1435,'0736','430700','常德市','111.691347,29.040225','city',''),(1436,'0744','430800','张家界市','110.479921,29.127401','city',''),(1437,'0737','430900','益阳市','112.355042,28.570066','city',''),(1438,'0735','431000','郴州市','113.032067,25.793589','city',''),(1439,'0746','431100','永州市','111.608019,26.434516','city',''),(1440,'0745','431200','怀化市','109.97824,27.550082','city',''),(1441,'0738','431300','娄底市','112.008497,27.728136','city',''),(1442,'0743','433100','湘西土家族苗族自治州','109.739735,28.314296','city',''),(1443,'','440000','广东省','113.280637,23.125178','province',''),(1444,'020','440100','广州市','113.280637,23.125178','city',''),(1445,'0751','440200','韶关市','113.591544,24.801322','city',''),(1446,'0755','440300','深圳市','114.085947,22.547','city',''),(1447,'0756','440400','珠海市','113.553986,22.224979','city',''),(1448,'0754','440500','汕头市','116.708463,23.37102','city',''),(1449,'0757','440600','佛山市','113.122717,23.028762','city',''),(1450,'0750','440700','江门市','113.094942,22.590431','city',''),(1451,'0759','440800','湛江市','110.364977,21.274898','city',''),(1452,'0668','440900','茂名市','110.919229,21.659751','city',''),(1453,'0758','441200','肇庆市','112.472529,23.051546','city',''),(1454,'0752','441300','惠州市','114.412599,23.079404','city',''),(1455,'0753','441400','梅州市','116.117582,24.299112','city',''),(1456,'0660','441500','汕尾市','115.364238,22.774485','city',''),(1457,'0762','441600','河源市','114.697802,23.746266','city',''),(1458,'0662','441700','阳江市','111.975107,21.859222','city',''),(1459,'0763','441800','清远市','113.051227,23.685022','city',''),(1460,'0769','441900','东莞市','113.746262,23.046237','city',''),(1461,'0760','442000','中山市','113.382391,22.521113','city',''),(1462,'0768','445100','潮州市','116.632301,23.661701','city',''),(1463,'0663','445200','揭阳市','116.355733,23.543778','city',''),(1464,'0766','445300','云浮市','112.044439,22.929801','city',''),(1465,'','450000','广西壮族自治区','108.320004,22.82402','province',''),(1466,'0771','450100','南宁市','108.320004,22.82402','city',''),(1467,'0772','450200','柳州市','109.411703,24.314617','city',''),(1468,'0773','450300','桂林市','110.299121,25.274215','city',''),(1469,'0774','450400','梧州市','111.297604,23.474803','city',''),(1470,'0779','450500','北海市','109.119254,21.473343','city',''),(1471,'0770','450600','防城港市','108.345478,21.614631','city',''),(1472,'0777','450700','钦州市','108.624175,21.967127','city',''),(1473,'0775','450800','贵港市','109.602146,23.0936','city',''),(1474,'0775','450900','玉林市','110.154393,22.63136','city',''),(1475,'0776','451000','百色市','106.616285,23.897742','city',''),(1476,'0774','451100','贺州市','111.552056,24.414141','city',''),(1477,'0778','451200','河池市','108.062105,24.695899','city',''),(1478,'0772','451300','来宾市','109.229772,23.733766','city',''),(1479,'0771','451400','崇左市','107.353926,22.404108','city',''),(1480,'','460000','海南省','110.33119,20.031971','province',''),(1481,'0898','460100','海口市','110.33119,20.031971','city',''),(1482,'0898','460200','三亚市','109.508268,18.247872','city',''),(1483,'0898','460300','三沙市','112.34882,16.831039','city',''),(1484,'0898','469001','五指山市','109.516662,18.776921','city',''),(1485,'0898','469002','琼海市','110.466785,19.246011','city',''),(1486,'0898','460400','儋州市','109.576782,19.517486','city',''),(1487,'0898','469005','文昌市','110.753975,19.612986','city',''),(1488,'0898','469006','万宁市','110.388793,18.796216','city',''),(1489,'0898','469007','东方市','108.653789,19.10198','city',''),(1490,'0898','469021','定安县','110.349235,19.684966','city',''),(1491,'0898','469022','屯昌县','110.102773,19.362916','city',''),(1492,'0898','469023','澄迈县','110.007147,19.737095','city',''),(1493,'0898','469024','临高县','109.687697,19.908293','city',''),(1494,'0898','469025','白沙黎族自治县','109.452606,19.224584','city',''),(1495,'0898','469026','昌江黎族自治县','109.053351,19.260968','city',''),(1496,'0898','469027','乐东黎族自治县','109.175444,18.74758','city',''),(1497,'0898','469028','陵水黎族自治县','110.037218,18.505006','city',''),(1498,'0898','469029','保亭黎族苗族自治县','109.70245,18.636371','city',''),(1499,'0898','469030','琼中黎族苗族自治县','109.839996,19.03557','city',''),(1500,'023','500000','重庆市','106.504962,29.533155','province',''),(1501,'023','500100','重庆市市辖区','106.504962,29.533155','city',''),(1502,'023','500200','重庆市郊县','108.170255,29.291965','city',''),(1503,'','510000','四川省','104.065735,30.659462','province',''),(1504,'028','510100','成都市','104.065735,30.659462','city',''),(1505,'0813','510300','自贡市','104.773447,29.352765','city',''),(1506,'0812','510400','攀枝花市','101.716007,26.580446','city',''),(1507,'0830','510500','泸州市','105.443348,28.889138','city',''),(1508,'0838','510600','德阳市','104.398651,31.127991','city',''),(1509,'0816','510700','绵阳市','104.741722,31.46402','city',''),(1510,'0839','510800','广元市','105.829757,32.433668','city',''),(1511,'0825','510900','遂宁市','105.571331,30.513311','city',''),(1512,'0832','511000','内江市','105.066138,29.58708','city',''),(1513,'0833','511100','乐山市','103.761263,29.582024','city',''),(1514,'0817','511300','南充市','106.082974,30.795281','city',''),(1515,'028','511400','眉山市','103.831788,30.048318','city',''),(1516,'0831','511500','宜宾市','104.630825,28.760189','city',''),(1517,'0826','511600','广安市','106.633369,30.456398','city',''),(1518,'0818','511700','达州市','107.502262,31.209484','city',''),(1519,'0835','511800','雅安市','103.001033,29.987722','city',''),(1520,'0827','511900','巴中市','106.753669,31.858809','city',''),(1521,'028','512000','资阳市','104.641917,30.122211','city',''),(1522,'0837','513200','阿坝藏族羌族自治州','102.221374,31.899792','city',''),(1523,'0836','513300','甘孜藏族自治州','101.963815,30.050663','city',''),(1524,'0834','513400','凉山彝族自治州','102.258746,27.886762','city',''),(1525,'','520000','贵州省','106.713478,26.578343','province',''),(1526,'0851','520100','贵阳市','106.713478,26.578343','city',''),(1527,'0858','520200','六盘水市','104.846743,26.584643','city',''),(1528,'0851','520300','遵义市','106.937265,27.706626','city',''),(1529,'0851','520400','安顺市','105.932188,26.245544','city',''),(1530,'0856','520600','铜仁市','109.191555,27.718346','city',''),(1531,'0859','522300','黔西南布依族苗族自治州','104.897971,25.08812','city',''),(1532,'0857','520500','毕节市','105.28501,27.301693','city',''),(1533,'0855','522600','黔东南苗族侗族自治州','107.977488,26.583352','city',''),(1534,'0854','522700','黔南布依族苗族自治州','107.517156,26.258219','city',''),(1535,'','530000','云南省','102.712251,25.040609','province',''),(1536,'0871','530100','昆明市','102.712251,25.040609','city',''),(1537,'0874','530300','曲靖市','103.797851,25.501557','city',''),(1538,'0877','530400','玉溪市','102.543907,24.350461','city',''),(1539,'0875','530500','保山市','99.167133,25.111802','city',''),(1540,'0870','530600','昭通市','103.717216,27.336999','city',''),(1541,'0888','530700','丽江市','100.233026,26.872108','city',''),(1542,'0879','530800','普洱市','100.972344,22.777321','city',''),(1543,'0883','530900','临沧市','100.08697,23.886567','city',''),(1544,'0878','532300','楚雄彝族自治州','101.546046,25.041988','city',''),(1545,'0873','532500','红河哈尼族彝族自治州','103.384182,23.366775','city',''),(1546,'0876','532600','文山壮族苗族自治州','104.24401,23.36951','city',''),(1547,'0691','532800','西双版纳傣族自治州','100.797941,22.001724','city',''),(1548,'0872','532900','大理白族自治州','100.225668,25.589449','city',''),(1549,'0692','533100','德宏傣族景颇族自治州','98.578363,24.436694','city',''),(1550,'0886','533300','怒江傈僳族自治州','98.854304,25.850949','city',''),(1551,'0887','533400','迪庆藏族自治州','99.706463,27.826853','city',''),(1552,'','540000','西藏自治区','91.132212,29.660361','province',''),(1553,'0891','540100','拉萨市','91.132212,29.660361','city',''),(1554,'0895','540300','昌都市','97.178452,31.136875','city',''),(1555,'0893','542200','山南地区','91.766529,29.236023','city',''),(1556,'0892','540200','日喀则市','88.885148,29.267519','city',''),(1557,'0896','542400','那曲地区','92.060214,31.476004','city',''),(1558,'0897','542500','阿里地区','80.105498,32.503187','city',''),(1559,'','540400','林芝市','94.362348,29.654693','city',''),(1560,'','610000','陕西省','108.948024,34.263161','province',''),(1561,'029','610100','西安市','108.948024,34.263161','city',''),(1562,'0919','610200','铜川市','108.979608,34.916582','city',''),(1563,'0917','610300','宝鸡市','107.14487,34.369315','city',''),(1564,'029','610400','咸阳市','108.705117,34.333439','city',''),(1565,'0913','610500','渭南市','109.502882,34.499381','city',''),(1566,'0911','610600','延安市','109.49081,36.596537','city',''),(1567,'0916','610700','汉中市','107.028621,33.077668','city',''),(1568,'0912','610800','榆林市','109.741193,38.290162','city',''),(1569,'0915','610900','安康市','109.029273,32.6903','city',''),(1570,'0914','611000','商洛市','109.939776,33.868319','city',''),(1571,'','620000','甘肃省','103.823557,36.058039','province',''),(1572,'0931','620100','兰州市','103.823557,36.058039','city',''),(1573,'0937','620200','嘉峪关市','98.277304,39.786529','city',''),(1574,'0935','620300','金昌市','102.187888,38.514238','city',''),(1575,'0943','620400','白银市','104.173606,36.54568','city',''),(1576,'0938','620500','天水市','105.724998,34.578529','city',''),(1577,'0935','620600','武威市','102.634697,37.929996','city',''),(1578,'0936','620700','张掖市','100.455472,38.932897','city',''),(1579,'0933','620800','平凉市','106.684691,35.54279','city',''),(1580,'0937','620900','酒泉市','98.510795,39.744023','city',''),(1581,'0934','621000','庆阳市','107.638372,35.734218','city',''),(1582,'0932','621100','定西市','104.626294,35.579578','city',''),(1583,'0939','621200','陇南市','104.929379,33.388598','city',''),(1584,'0930','622900','临夏回族自治州','103.212006,35.599446','city',''),(1585,'0941','623000','甘南藏族自治州','102.911008,34.986354','city',''),(1586,'','630000','青海省','101.778916,36.623178','province',''),(1587,'0971','630100','西宁市','101.778916,36.623178','city',''),(1588,'0972','630200','海东市','102.10327,36.502916','city',''),(1589,'0970','632200','海北藏族自治州','100.901059,36.959435','city',''),(1590,'0973','632300','黄南藏族自治州','102.019988,35.517744','city',''),(1591,'0974','632500','海南藏族自治州','100.619542,36.280353','city',''),(1592,'0975','632600','果洛藏族自治州','100.242143,34.4736','city',''),(1593,'0976','632700','玉树藏族自治州','97.008522,33.004049','city',''),(1594,'0977','632800','海西蒙古族藏族自治州','97.370785,37.374663','city',''),(1595,'','640000','宁夏回族自治区','106.278179,38.46637','province',''),(1596,'0951','640100','银川市','106.278179,38.46637','city',''),(1597,'0952','640200','石嘴山市','106.376173,39.01333','city',''),(1598,'0953','640300','吴忠市','106.199409,37.986165','city',''),(1599,'0954','640400','固原市','106.285241,36.004561','city',''),(1600,'0955','640500','中卫市','105.189568,37.514951','city',''),(1601,'','650000','新疆维吾尔自治区','87.617733,43.792818','province',''),(1602,'0991','650100','乌鲁木齐市','87.617733,43.792818','city',''),(1603,'0990','650200','克拉玛依市','84.873946,45.595886','city',''),(1604,'','650400','吐鲁番市','89.184078,42.947613','city',''),(1605,'0902','652200','哈密地区','93.51316,42.833248','city',''),(1606,'0994','652300','昌吉回族自治州','87.304012,44.014577','city',''),(1607,'0909','652700','博尔塔拉蒙古自治州','82.074778,44.903258','city',''),(1608,'0996','652800','巴音郭楞蒙古自治州','86.150969,41.768552','city',''),(1609,'0997','652900','阿克苏地区','80.265068,41.170712','city',''),(1610,'0908','653000','克孜勒苏柯尔克孜自治州','76.172825,39.713431','city',''),(1611,'0998','653100','喀什地区','75.989138,39.467664','city',''),(1612,'0903','653200','和田地区','79.92533,37.110687','city',''),(1613,'0999','654000','伊犁哈萨克自治州','81.317946,43.92186','city',''),(1614,'0901','654200','塔城地区','82.985732,46.746301','city',''),(1615,'0906','654300','阿勒泰地区','88.13963,47.848393','city',''),(1616,'0993','659001','石河子市','86.041075,44.305886','city',''),(1617,'0997','659002','阿拉尔市','81.285884,40.541914','city',''),(1618,'0998','659003','图木舒克市','79.077978,39.867316','city',''),(1619,'0994','659004','五家渠市','87.526884,44.167401','city',''),(1620,'0906','659005','北屯市','87.824932,47.353177','city',''),(1621,'0996','659006','铁门关市','85.501218,41.827251','city',''),(1622,'0909','659007','双河市','82.353656,44.840524','city',''),(1623,'0999','659008','可克达拉市','80.63579,43.6832','city',''),(1624,'1853','820000','澳门特别行政区','113.54909,22.198951','province',''),(1625,'1853','820001','花地瑪堂區','113.5528956,22.20787','district',''),(1626,'1853','820002','花王堂區','113.5489608,22.1992075','district',''),(1627,'1853','820003','望德堂區','113.5501828,22.19372083','district',''),(1628,'1853','820004','大堂區','113.5536475,22.18853944','district',''),(1629,'1853','820005','風順堂區','113.5419278,22.18736806','district',''),(1630,'1853','820006','嘉模堂區','113.5587044,22.15375944','district',''),(1631,'1853','820007','路氹填海區','113.5695992,22.13663','district',''),(1632,'1853','820008','聖方濟各堂區','113.5599542,22.12348639','district',''); /*!40000 ALTER TABLE `amap` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2016-02-18 3:12:53
- export2csv.sql
select * from amap into outfile '/tmp/test.csv' fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n';
基于这个API,可以做的事情很多,比如查某个区域的某个类别的店铺信息(我查过静安区的美甲店分布)
也可以从多个地图API查询相同信息,然后做交叉比对
代码在http://www.cnblogs.com/smarterplanet/p/4700375.html基础上做了修正,有兴趣的可以访问https://gist.github.com/alitrack/6b93032165c8d9687b84adc26a33ca70