如何使用GoogleMapFeedAPI获取使用Python的GoogleMaps列表?
我想用Python创建一个脚本,下载我在GoogleMaps上创建的所有地图的当前KML文件 要手动执行此操作,我可以使用以下方法:如何使用GoogleMapFeedAPI获取使用Python的GoogleMaps列表?,python,google-maps,kml,Python,Google Maps,Kml,我想用Python创建一个脚本,下载我在GoogleMaps上创建的所有地图的当前KML文件 要手动执行此操作,我可以使用以下方法: http://maps.google.com.br/maps/ms?msid=USER_ID.MAP_ID&msa=0&output=kml 其中,USER\u ID是谷歌用来识别我的固定数字,MAP\u ID是由右上角的链接图标生成的单个地图标识符 这不是很简单,因为我必须手动浏览谷歌地图上的“我的位置”页面,并逐个获取链接 发件人: 地图提要
http://maps.google.com.br/maps/ms?msid=USER_ID.MAP_ID&msa=0&output=kml
其中,USER\u ID
是谷歌用来识别我的固定数字,MAP\u ID
是由右上角的链接
图标生成的单个地图标识符
这不是很简单,因为我必须手动浏览谷歌地图上的“我的位置”页面,并逐个获取链接
发件人:
地图提要是用户创建的地图的提要
此提要的完整获取URI为:
此提要返回经过身份验证的用户的所有映射的列表
**网页上说这项服务已经不可用了,所以我想知道现在是否有办法做到这一点
那么,问题是:有没有办法获取/下载我所有地图的地图ID列表,最好使用Python?
感谢您阅读我发现的一种快速而肮脏的方式,它完全跳过了Google Maps API,可能在不久的将来会停止,是这样的:
# coding: utf-8
import urllib, re
from BeautifulSoup import BeautifulSoup as bs
uid = '200931058040775970557'
start = 0
shown = 1
while True:
url = 'http://maps.google.com/maps/user?uid='+uid+'&ptab=2&start='+str(start)
source = urllib.urlopen(url).read()
soup = bs(source)
maptables = soup.findAll(id=re.compile('^map[0-9]+$'))
for table in maptables:
for line in table.findAll('a', 'maptitle'):
mapid = re.search(uid+'\.([^"]*)', str(line)).group(1)
mapname = re.search('>(.*)</a>', str(line)).group(1).strip()[:-2]
print shown, mapid, mapname
shown += 1
# uncomment if you want to download the KML files:
# urllib.urlretrieve('http://maps.google.com.br/maps/ms?msid=' + uid + '.' + str(mapid) +
'&msa=0&output=kml', mapname + '.kml')
if '<span>Next</span>' in str(source):
start += 5
else:
break
#编码:utf-8
导入urllib,re
从BeautifulSoup导入BeautifulSoup作为bs
uid='200931058040775970557'
开始=0
所示=1
尽管如此:
url='1〕http://maps.google.com/maps/user?uid='+uid+'&ptab=2&start='+str(start)
source=urllib.urlopen(url.read())
汤=bs(来源)
maptables=soup.findAll(id=re.compile(“^map[0-9]+$”)
对于maptables中的表:
对于table.findAll('a','maptitle')中的行:
mapid=re.search(uid+'\.([^“]*),str(line)).group(1)
mapname=re.search('>(.*),str(line)).group(1.strip()[:-2]
显示的打印、mapid、mapname
显示+=1
#如果要下载KML文件,请取消注释:
#urllib.urlretrieve('http://maps.google.com.br/maps/ms?msid=“+uid+”.+str(mapid)+
“&msa=0&output=kml',mapname+'.kml')
如果str中的“下一步”(源):
开始+=5
其他:
打破
当然,它只是打印一个编号的列表,但从那里保存字典和/或通过
&output=KML
url自动下载KML,这很自然。这个问题的正确答案涉及使用Google Maps数据API、HTML接口,顺便提一句,该接口不受欢迎,但仍然以更正式的方式解决了我的需要,or至少比解析网页更有说服力。如下所示:
# coding: utf-8
import urllib2, urllib, re, getpass
username = 'heltonbiker'
senha = getpass.getpass('Senha do usuário ' + username + ':')
dic = {
'accountType': 'GOOGLE',
'Email': (username + '@gmail.com'),
'Passwd': senha,
'service': 'local',
'source': 'helton-mapper-1'
}
url = 'https://www.google.com/accounts/ClientLogin?' + urllib.urlencode(dic)
output = urllib2.urlopen(url).read()
authid = output.strip().split('\n')[-1].split('=')[-1]
request = urllib2.Request('http://maps.google.com/maps/feeds/maps/default/full')
request.add_header('Authorization', 'GoogleLogin auth=%s' % authid)
source = urllib2.urlopen(request).read()
for link in re.findall('<link rel=.alternate. type=.text/html. href=((.)[^\1]*?)>', source):
s = link[0]
if 'msa=0' in s:
print s
#编码:utf-8
导入urllib2、urllib、re、getpass
用户名='heltonbiker'
senha=getpass.getpass('senha do usuário'+用户名+':')
dic={
“accountType”:“GOOGLE”,
“Email”:(用户名+“@gmail.com”),
“Passwd”:senha,
“服务”:“本地”,
“来源”:“helton-mapper-1”
}
url='1〕https://www.google.com/accounts/ClientLogin?'+urllib.urlencode(dic)
output=urlib2.urlopen(url.read())
authid=output.strip().split('\n')[-1]。split('=')[-1]
请求=urllib2。请求('http://maps.google.com/maps/feeds/maps/default/full')
请求。添加标题('Authorization','GoogleLogin auth=%s'%authid)
source=urllib2.urlopen(请求).read()
关于findall(“”,来源)中的链接:
s=链接[0]
如果s中的“msa=0”:
印刷品
我带着一大堆其他问题来到这里,很多人帮了我很多,所以我希望这段代码可以帮助将来尝试这样做的任何人。我现在接受我自己的答案,但我真的打算用另一个更强大的(不太依赖谷歌的页面布局)来代替它我也一直在看这个…这个端点还在工作吗?@docchang好吧,你可以测试它,但现在已经有一段时间了…从那时起,谷歌的很多事情都发生了变化。我的答案是“嗯,我真的不知道”。。。