2012-05-04 56 views
0

我想从http://www.google.com/ig/api?weather=获取天气我用这个C#谷歌的天气XML越来越

// 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; 

我使用的URL http://www.google.com/ig/api?weather=vilnius&hl=lt但在英语获取信息,我无法找到问题,请帮助:)

+0

当我打开我的浏览器的网址,我没有看到任何英文单词,但只有立陶宛。在浏览器中打开结果时结果如何? – Yogu

+0

英文;(也许问题是在位置设置在PC – Wizard

+0

我在德国,我的浏览器也是德国人,所以这应该是没有问题的 – Yogu

回答

1

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

英语成绩:http://www.google.com/ig/api?weather=vilnius&hl=lt

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

+0

看到我的第一篇文章我不使用'&'但url仍然是错误的 – Wizard

+0

错误是什么意思?服务器似乎没有返回有效的XML从我可以告诉,但没有任何错误的url本身。 –

+0

错误'无效字符在给定的编码。第1行,位置473.' – Wizard