google api 很強大,用python調用這些API的方法:
1.Google Map Api
>>>import urllib,urllib2
>>>val = {'q':'New York', 'sensor':'false','output':'xml','oe':'utf-8'} #還有個key的選項,如果申請了密鑰可以加進去,但是本地測試加不加都可以
>>> urllib2.urlopen('http://maps.google.com/maps/geo?%s'%urllib.urlencode(val)).read()
得到xml如下:
'<?xml version="1.0" encoding="UTF-8" ?>\n<kml xmlns="http://earth.google.com/km
l/2.0"><Response>\n <name>New York</name>\n <Status>\n <code>200</code>\n
<request>geocode</request>\n </Status>\n <Placemark id="p1">\n <address>N
ew York, NY, USA</address>\n <AddressDetails Accuracy="4" xmlns="urn:oasis:na
mes:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><Cou
ntryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</Admini
strativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>New York</Sub
AdministrativeAreaName><Locality><LocalityName>New York</LocalityName></Locality
></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>\n <
ExtendedData>\n <LatLonBox north="40.8495342" south="40.5788964" east="-73.
7498543" west="-74.2620919" />\n </ExtendedData>\n <Point><coordinates>-74
.0059731,40.7143528,0</coordinates></Point>\n </Placemark>\n</Response></kml>\n
'
解析這個xml就可以了
2. Google Search API