python hack google api

 

google api 很强大,用python调用这些API的方法:python

1.Google Map Apiapi

>>>import urllib,urllib2ide

>>>val = {'q':'New York', 'sensor':'false','output':'xml','oe':'utf-8'}  #还有个key的选项,若是申请了密钥能够加进去,可是本地测试加不加均可以post

>>> urllib2.urlopen('http://maps.google.com/maps/geo?%s'%urllib.urlencode(val)).read()测试

获得xml以下:google

'<?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
'url

解析这个xml就能够了spa

2. Google Search API (貌似已通过期了)code

相关文章
相关标签/搜索