我在分析谷歌天气时收到以下错误。任何人都知道这个解决方案,一直在到处寻找,但没有乐趣
Entity: line 2: parser error : AttValue: " or ' expected
$lang ='English';
$place=urlencode($weather);
$place = utf8_encode($place);
$url = 'http://www.google.com/ig/api?weather='.$place.',$&hl='.$lang.'';
$ch = curl_init();
//Set CURL options
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
$raw_data = curl_exec($ch);
//close CURL cause we dont need it anymore
curl_close($ch);
$xml = simplexml_load_string($raw_data);
众所周知,谷歌天气API会不时抛出403个错误。当这种情况发生时,请求将得到HTTP 403响应和HTML错误文档的响应。由于错误文档不是有效的XML,因此无法使用simplexml_load_string
对其进行解析。
您应该使用另一个天气API。