找了很多都只有英文,并且 Hong Kong, Macao, Taiwan都是单独列出来的。
发现QQ注册页的国家和城市数据比较全面。可以把它分离出来。
数据来源 http://zc.qq.com/chs/index.html
js:http://4.url.cn/zc/chs/js/10062/location_chs.js
建数据库:
CREATE TABLE `t_location` ( `location_id` int(11) NOT NULL AUTO_INCREMENT, `abbr` varchar(30) NOT NULL DEFAULT ‘‘, `name_chs` varchar(30) NOT NULL DEFAULT ‘‘, `name_cht` varchar(30) NOT NULL DEFAULT ‘‘, `name_en` varchar(30) NOT NULL DEFAULT ‘‘, `location_type` tinyint(1) NOT NULL DEFAULT ‘0‘ COMMENT ‘0:country,1:state,2:city‘, `parent_id` int(11) NOT NULL DEFAULT ‘0‘ COMMENT ‘parent location_id‘, `is_visible` tinyint(1) NOT NULL DEFAULT ‘1‘ COMMENT ‘0:visible,1:invisible‘, PRIMARY KEY (`location_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
获取js对象
var local; function initLocation(data) { local = data; } $.getScript(‘http://4.url.cn/zc/chs/js/10062/location_chs.js‘);
获取 sql
var countryId = 0; var locationId = 0; var maxCountryId = 0; var countrySql = ‘‘; var provinceSql = ‘‘; $.each(local, function(k,v){ if(!v.n.length) { return; } countryId++; locationId++; countrySql += ‘insert into t_location(location_id, abbr, name_chs) values(‘+countryId+‘,\‘‘+k+‘\‘,\‘‘+ v.n + ‘\‘);‘; $.each(v, function(k2,v2){ if(typeof(v2.n) === ‘undefined‘ || !v2.n.length) { return; } provinceSql += ‘insert into t_location(parent_id,location_type, name_chs) values(\‘‘+countryId+‘\‘,1,\‘‘+ v2.n + ‘\‘);‘; locationId++; }); }); $(document.body).html(‘‘); $(document.body).append(countrySql+provinceSql); var pid = countryId; var citySql = ‘‘; $.each(local, function(k,v){ if(!v.n.length) { return; } locationId++; $.each(v, function(k2,v2){ if(typeof(v2.n) === ‘undefined‘ || !v2.n.length) { return; } pid++; for(var p in v2){ if(p === ‘n‘ || !v2[p].n.length) { continue; } citySql += ‘insert into t_location(parent_id,location_type, name_chs) values(\‘‘+pid+‘\‘,2,\‘‘+ v2[p].n + ‘\‘);‘; } }); }); $(document.body).append(citySql);
原文:http://my.oschina.net/u/573015/blog/350397