c#google weather xml getting

时间:2012-05-04 20:33:50

标签: c# asp.net google-weather-api

我希望从http://www.google.com/ig/api?weather=获取天气我使用此

    // load xml result from Google weather
    var addr = WebUtility.HtmlEncode("http://www.google.com/ig/api?weather=vilnius&hl=lt");
    XDocument xd = XDocument.Load(addr);


// navigate to current conditions node
var current_conditions = from currentCond in xd.Root.Descendants("current_conditions")
select currentCond;

// navigate to Forecast info node
var forcastInfo = from forecastinfo in xd.Root.Descendants("forecast_information")
select forecastinfo;

我使用网址http://www.google.com/ig/api?weather=vilnius&hl=lt但是信息是英文的,我找不到问题请帮助:)

1 个答案:

答案 0 :(得分:1)

查看我对original question的回答 - 不需要WebUtility.HtmlEncode,因为你得到“amp; hl = lt”查询参数而不是“hl = lt”。

英文结果:http://www.google.com/ig/api?weather=vilnius&hl=lt

非英语结果:http://www.google.com/ig/api?weather=vilnius&hl=lt