python hack google api

來源:互聯網
上載者:User

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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.