将URL编码为谷歌可读的格式

时间:2012-08-22 18:23:58

标签: python url encoding character-encoding

我想知道如何对网址进行编码,以便将其作为参数传递到Google地图中?

https://maps.google.com/maps?q=https:%2F%2Fdl.dropbox.com%2Fu%2F94943007%2Ffile.kml&hl=en&sll=32.824552,-117.108978&sspn=0.889745,1.575165&t=m&z=4

您可以看到该网址作为参数传递到maps.google.com/ url

问题是,如果我从像http://www.microsoft.com/somemap.kml这样的网址开始,我该如何对此网址进行编码,以便我可以将其传入其中

1 个答案:

答案 0 :(得分:2)

该过程称为URL encoding

>>> urllib.quote('https://dl.dropbox.com/u/94943007/file.kml', '')
'https%3A%2F%2Fdl.dropbox.com%2Fu%2F94943007%2Ffile.kml'