您的位置:首页 > 其它

获取全球行政区划

jerrism 2020-05-11 04:13 225 查看 https://blog.csdn.net/jerrism/

在qq的安装目录下找到

Tencent\QQIntl\I18N\2052\LocList.xml
,按照xml格式存储,其中国内精确到区县,国外精确到市。若要将其转换成csv:

from lxml import etree

xml = etree.parse(r"C:\Users\hmy\Documents\行政区划\LocList.xml")
CountryRegion = xml.xpath('//CountryRegion')
with open(r'C:\Users\hmy\Documents\行政区划\LocList.csv', encoding='utf-8', mode='a')as f:
for cr in CountryRegion:
cr_name = ''.join((cr.xpath('./@Name') or [''])[0].split())
State = cr.xpath('.//State')
for s in State:
s_name = ''.join((s.xpath('./@Name') or [''])[0].split())
City = s.xpath('.//City')
for c in City:
c_name = ''.join((c.xpath('./@Name') or [''])[0].split())
Region = c.xpath('.//Region')
if Region:
for r in Region:
r_name = ''.join((r.xpath('./@Name') or [''])[0].split())
f.write(','.join((cr_name, s_name, c_name, r_name)) + '\n')
else:
f.write(','.join((cr_name, s_name, c_name, '')) + '\n')

要获取英文名,则在国际版qq的安装目录中查找对应的1033目录。

jerrism 原创文章 16获赞 1访问量 445 关注 私信
标签: