shirobert 发表于 2018-8-13 06:09:42

python hack google api-Lyncmaster的博客


  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=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>\n<kml xmlns=&quot;http://earth.google.com/km
  l/2.0&quot;><Response>\n<name>New York</name>\n<Status>\n    <code>200</code>\n

  <request>geocode</request>\n</Status>\n<Placemark>  ew York, NY, USA</address>\n    <AddressDetails Accuracy=&quot;4&quot; xmlns=&quot;urn:oasis:na
  mes:tc:ciq:xsdschema:xAL:2.0&quot;><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=&quot;40.8495342&quot; south=&quot;40.5788964&quot; east=&quot;-73.
  7498543&quot; west=&quot;-74.2620919&quot; />\n    </ExtendedData>\n    <Point><coordinates>-74
  .0059731,40.7143528,0</coordinates></Point>\n</Placemark>\n</Response></kml>\n
  '
  解析这个xml就可以了
  2. Google Search API (貌似已经过期了)
页: [1]
查看完整版本: python hack google api-Lyncmaster的博客