最简单的用法:
import httplib2
import libxml2
http = httplib2.Http()
response,content=http.request('http://www.google.com/ig/api?hl=en_us&weather=kunming','GET')
doc = libxml2.parseDoc(content)
print doc
doc.freeDoc()
输出如下:
<?xml version="1.0"?>
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
<forecast_information>
<city data="Kunming, Yunnan"/>
<postal_code data="kunming"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2012-05-08"/>
<current_date_time data="2012-05-09 03:00:00 +0000"/>
<unit_system data="US"/>
</forecast_information>
<current_conditions>
<condition data="Clear"/>
<temp_f data="64"/>
<temp_c data="18"/>
<humidity data="Humidity: 83%"/>
<icon data="/ig/images/weather/sunny.gif"/>
<wind_condition data="Wind: S at 7 mph"/>
</current_conditions>
<forecast_conditions>
<day_of_week data="Tue"/>
<low data="57"/>
<high data="81"/>
<icon data="/ig/images/weather/chance_of_storm.gif"/>
<condition data="Chance of Storm"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Wed"/>
<low data="59"/>
<high data="84"/>
<icon data="/ig/images/weather/mostly_sunny.gif"/>
<condition data="Mostly Sunny"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Thu"/>
<low data="59"/>
<high data="81"/>
<icon data="/ig/images/weather/thunderstorm.gif"/>
<condition data="Thunderstorm"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Fri"/>
<low data="59"/>
<high data="84"/>
<icon data="/ig/images/weather/mostly_sunny.gif"/>
<condition data="Partly Sunny"/>
</forecast_conditions>
</weather>
</xml_api_reply>