如何使用Google Map Feed API获取我的Google Maps使用Python的列表? [英] How can I use Google Map Feed API to get a list of my Google Maps using Python?

查看:130
本文介绍了如何使用Google Map Feed API获取我的Google Maps使用Python的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Python中创建一个脚本,下载我在Google Maps上创建的所有地图的当前KML文件。

要手动执行此操作,我可以使用此:

  http://maps.google.com.br/maps/ms?msid=USER_ID.MAP_ID&msa= 0& output = kml 

其中 USER_ID 是Google用来识别我的常数,而 MAP_ID 是由顶部链接上的链接图标生成的单个映射标识符,



这不是非常简单,因为我必须手动浏览Google地图上的我的地点页面,并逐个获取链接。



Google地图API HTTP协议参考


地图Feed是用户创建地图的提要。



此提要的完整GET URI为:

http://maps.google.com/maps/feeds/maps/default/full



此提要返回经过身份验证的用户的所有地图列表。


**页面说这个服务不再可用,所以我想知道现在是否有办法做到这一点。



所以问题是:Is有一种方法可以获取/下载我所有地图的MAP_ID列表,最好使用Python?



感谢阅读

解决方案

这个问题的正确答案涉及到使用Google Maps Data API,HTML界面,这种方式已被弃用,但仍以更官方的方式解决了我的需求,或者至少比分析网页更令人信服。这里是:

 #编码:utf-8 

导入urllib2,urllib,re,getpass

username ='heltonbiker'
senha = getpass.getpass('Senha dousuário'+ username +':')

dic = {
'accountType':'GOOGLE',
'电子邮件':(用户名+'@ 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 re.findall('< link rel = .alternate.type = .text / html。href =((。)[^ \1] *?)>',source):
s = link [0]
if'msa = 0 's:
print s

我带着这个解决方案带来了一堆其他问题在SO中,很多人帮助了我很多,所以我希望这个代码可以帮助其他人在未来尝试这样做。


I want to create a script in Python which downloads the current KML files of all the Maps I created on Google Maps.

To do so manually, I can use this:

http://maps.google.com.br/maps/ms?msid=USER_ID.MAP_ID&msa=0&output=kml

where USER_ID is a constant number Google uses to identify me, and MAP_ID is the individual map identifier generated by the link icon on top-right corner.

This is not very straightforward, because I have to manually browse "My Places" page on Google Maps, and get the links one by one.

From Google Maps API HTTP Protocol Reference:

The Map Feed is a feed of user-created maps.

This feed's full GET URI is:

http://maps.google.com/maps/feeds/maps/default/full

This feed returns a list of all maps for the authenticated user.

** The page says this service is no longer available, so I wonder if there is a way to do the same in the present.

So, the question is: Is there a way to get/download the list of MAP_IDs of all my maps, preferrably using Python?

Thanks for reading

解决方案

The correct answer to this question involves using Google Maps Data API, HTML interface, which by the way is deprecated but still solves my need in a more official way, or at least more convincing than parsing a web page. Here it goes:

# 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

I arrived with this solution with a bunch of other questions in SO, and a lot of people helped me a lot, so I hope this code might help anyone else trying to do so in the future.

这篇关于如何使用Google Map Feed API获取我的Google Maps使用Python的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆